Skip to content

Instantly share code, notes, and snippets.

@corrafig
Last active December 28, 2020 19:47
Show Gist options
  • Save corrafig/01d5eee65742f641d88f097a872c1b19 to your computer and use it in GitHub Desktop.
Save corrafig/01d5eee65742f641d88f097a872c1b19 to your computer and use it in GitHub Desktop.
Example of using org mode as HTTP client. Requires ob-http.
* Configuration
#+name: current_env
: staging
#+name: get-env
#+begin_src python :var key="host" :var env=current_env :results silent
return {
"staging": {"host": "httpbin.org", "key": "staging-api-key"},
"prod": {"host": "httpbin.org", "key": "production-api-key"},
}[env][key]
#+end_src
* API tests
:PROPERTIES:
:header-args: :var host=get-env :var key=get-env("key") :schema https :pretty
:END:
#+BEGIN_SRC http
GET ${host}/anything
x-api-key: ${key}
#+END_SRC
#+RESULTS:
#+begin_example
{
"args": {},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Host": "httpbin.org",
"User-Agent": "curl/7.72.0",
"X-Amzn-Trace-Id": "Root=1-5fea33c9-762b66ad616863ba65cf0ce5",
"X-Api-Key": "staging-api-key"
},
"json": null,
"method": "GET",
"origin": "000.000.000.000",
"url": "http://httpbin.org/anything"
}
#+end_example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment