http request in org-mode babel, requires curl
#+BEGIN_SRC http :pretty GET https://api.github.com/repos/zweifisch/ob-http/languages Accept: application/vnd.github.moondragon+json #+END_SRC #+RESULTS: : { : "Emacs Lisp": 8170 : }
To use ob-http
in an org-babel
source block, the http language must be enabled in the custom org-babel-load-languages
alist. Alternatively, running the following snippet during initialization will enable the mode.
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t)
(http . t)))
option | curl | example |
---|---|---|
:proxy | -x | :proxy localhost:8118 |
:noproxy | --noproxy * | N/A |
:cookie-jar | --cookie-jar | :cookie-jar username |
:cookie | --cookie | :cookie username |
:max-time | --max-time | default is 10 |
:user | --user | :user admin:passwd |
:pretty | N/A | :pretty use Content-Type , to overwrite :pretty json |
:select | N/A | :select path path will be passed to jq for json or pup for html or xmlstarlet for xml |
:get-header | N/A | :get-header X-Subject-Token |
:curl | N/A | :curl --insecure --compressed additional arguments for curl |
:resolve | --resolve | :resolve example.com:80:127.0.0.1,example.com:443:127.0.0.1 |
#+BEGIN_SRC http :pretty GET http://httpbin.org/user-agent User-Agent: ob-http #+END_SRC #+RESULTS: : { : "user-agent": "ob-http" : }
#+BEGIN_SRC http :pretty POST http://httpbin.org/post Content-Type: application/json { "key": "value" } #+END_SRC #+RESULTS: #+begin_example { "url": "http://httpbin.org/post", "json": { "key": "value" }, "headers": { "User-Agent": "curl/7.35.0", "Host": "httpbin.org", "Content-Type": "application/json", "Content-Length": "18", "Accept": "*/*" }, "form": {}, "files": {}, "data": "{ \"key\": \"value\"}", "args": {} } #+end_example
#+BEGIN_SRC http :pretty PATCH http://httpbin.org/patch key=value&foo=value #+END_SRC #+RESULTS: #+begin_example { "url": "http://httpbin.org/patch", "origin": "116.227.144.38", "json": null, "headers": { "User-Agent": "curl/7.35.0", "Host": "httpbin.org", "Content-Type": "application/x-www-form-urlencoded", "Content-Length": "19", "Accept": "*/*" }, "form": { "key": "value", "foo": "value" }, "files": {}, "data": "", "args": {} } #+end_example
#+HEADER: :var name="ob-http" #+HEADER: :var password="secret" #+BEGIN_SRC http :select .json POST http://httpbin.org/post Content-Type: application/json { "auth": { "name": "${name}", "password": "${password}" } } #+END_SRC #+RESULTS: : { : "auth": { : "password": "secret", : "name": "ob-http" : } : }
supported headers:
- pretty
- proxy
- noproxy
- cookie
- schema
- host
- port
- user
- max-time
* api test :PROPERTIES: :header-args: :var token="secret" :host httpbin.org :pretty :END: #+BEGIN_SRC http POST /post Content-Type: application/json X-Auth-Token: ${token} #+END_SRC #+RESULTS: #+begin_example { "url": "http://httpbin.org/post", "json": null, "headers": { "X-Auth-Token": "secret", "User-Agent": "curl/7.35.0", "Host": "httpbin.org", "Content-Type": "application/json", "Accept": "*/*" }, "form": {}, "files": {}, "data": "", "args": {} } #+end_example
#+BEGIN_SRC http :file zweifisch.jpeg GET https://avatars.githubusercontent.com/u/447862?v=3 #+END_SRC
#+RESULTS: [[file:zweifisch.jpeg]]