Skip to content

Latest commit

 

History

History
127 lines (94 loc) · 3.13 KB

http.md

File metadata and controls

127 lines (94 loc) · 3.13 KB

HTTP

Resources

Tools

HTTPie

HTTPie is a better curl. Read the documentation.

Simple GET or DELETE requests (http:// is optional, and for localhost, even the hostname is):

http get http://localhost:3001/api/stuff
http delete :3001/api/stuff

Data is implicitly sent as JSON:

http PUT example.org name=John [email protected]

Add some custom headers:

http example.org \
  User-Agent:Bacon/1.0 \
  'Cookie:valued-visitor=yes;foo=bar' \
  X-Foo:Bar \
  Referer:http://httpie.org/

HTTP Prompt

HTTP Prompt is an interactive command-line HTTP client featuring autocomplete and syntax highlighting.

Installation:

sudo apt install python-pip
pip install --user http-prompt
# pip installs to ~/.local/bin/, but does not tell anyone.
# check if this is part of your $PATH, e.g. for my fish setup:
path
add_path ~/.local/bin/

Usage (see the user guide for details):

$ http-prompt localhost:3001

> cd /api/resource
> get                             # sends HTTP request: GET /api/resource# response, paged and /w syntax highlighting

> Content-Type:application/json   # set a header
# set some body parameters as JSON:
> number:=1234
> is_ok:=true
> names:=["foo","bar"]
> user:='{"username": "foo", "password": "bar"}'
> post                            # send the POST request with header and body

HTTP Prompt is using httpie, and you can preview the calls it will make with

> httpie post   # or any other HTTP verb

Note that headers, body data, etc. is persisted, so it will be included in every request. You can check the current environment with env and remove stuff with rm:

> env
cd http://localhost:3001/api/stuff
'jsondata:={"crazy": "object here"}'
Content-Type:application/json
> rm -h Content-Type              # remove that header
> rm *                            # clear everything

Insomnia

Insomnia is a graphical API client (Rest, GraphQL, WS, …), similar to Postman. Can store collections of API endpoints, supports multiple environments, etc. Free version is sufficient for most stuff.

jq

jq is like sed for JSON data.

Can be used together with curl or http to filter out data from lengthy JSON results. Minimal example:

> http some.web-api.org/stuff
{ "foo": "bar", "otherStuff": "i dont care for", ... }

> http some.web-api.org/stuff | jq .foo
"bar"

Dealing with arrays:

> http some.web-api.org/list
[{ "foo": 1, "bar": "a" }, { "foo": 2, "bar": "b" }, ...]

> http some.web-api.org/list | jq '.[] | .foo'
1
2