https://github.com/zweifisch/ob-http
make http request within org-mode babel
https://github.com/zweifisch/ob-http
curl http-client org-babel org-mode
Last synced: about 1 month ago
JSON representation
make http request within org-mode babel
- Host: GitHub
- URL: https://github.com/zweifisch/ob-http
- Owner: zweifisch
- License: gpl-3.0
- Created: 2015-02-01T07:40:32.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-07-09T16:06:20.000Z (10 months ago)
- Last Synced: 2025-03-30T03:08:41.147Z (about 2 months ago)
- Topics: curl, http-client, org-babel, org-mode
- Language: Emacs Lisp
- Size: 64.5 KB
- Stars: 267
- Watchers: 8
- Forks: 30
- Open Issues: 21
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
* ob-http
[[http://melpa.org/#/ob-http][file:http://melpa.org/packages/ob-http-badge.svg]]
[[http://stable.melpa.org/#/ob-http][file:http://stable.melpa.org/packages/ob-http-badge.svg]]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
: : }** setup
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.
#+BEGIN_SRC emacs-lisp
(org-babel-do-load-languages
'org-babel-load-languages
'((emacs-lisp . t)
(http . t)))
#+END_SRC** options
| 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 [[https://stedolan.github.io/jq/][jq]] for json or [[https://github.com/EricChiang/pup][pup]] for html or [[http://xmlstar.sourceforge.net/][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= |** examples
**** set arbitrary header: #+BEGIN_SRC http :pretty
: GET http://httpbin.org/user-agent
: User-Agent: ob-http
: #+END_SRC
:
: #+RESULTS:
: : {
: : "user-agent": "ob-http"
: : }**** json
: #+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**** form submit
: #+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**** variable
: #+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"
: : }
: : }**** use properties
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**** files
: #+BEGIN_SRC http :file zweifisch.jpeg
: GET https://avatars.githubusercontent.com/u/447862?v=3
: #+END_SRC: #+RESULTS:
: [[file:zweifisch.jpeg]]