01 Jan 2022
Trimming newline on code block variable
Today I found ob-http and decided to try it out a little. I quickly ran into a problem of a trailing newline. Basically I tried to do something like this:
#+begin_src http :select .id :cache yes POST /foo Content-Type: application/json { "foo": "toto", "bar": "tata" } #+end_src #+begin_example 48722051-f81b-433f-acb4-a65d961ec841 #+end_example #+begin_src http POST /foo/${id}/fix #+end_src
The trailing newline messes up the URL though, and the second code block fails.
I found two ways to deal with it, using a table and using org-sbe
Using a table
#+begin_src http :select .id :cache yes :results table POST /foo Content-Type: application/json { "foo": "toto", "bar": "tata" } #+end_src #+begin_example | 48722051-f81b-433f-acb4-a65d961ec841 | #+end_example #+begin_src http POST /foo/${id}/fix #+end_src
Using org-sbe
#+begin_src http :select .id :cache yes POST /foo Content-Type: application/json { "foo": "toto", "bar": "tata" } #+end_src #+begin_example 48722051-f81b-433f-acb4-a65d961ec841 #+end_example #+begin_src http POST /foo/${id}/fix #+end_src