HTTPie: Simpler Alternative to Curl

Here's an easy-to-use alternative to curl, HTTPie.

Install

sudo apt install httpie

curl Way

Here's a post to a /api/users API, that sends a basic "person" payload in json:

curl http://localhost:3000/api/users -H "Content-Type: application/json" -d '{"name": "Curly"}'

Deal with headers. Handle proper json quotes. A bit hairy to look at and type on a terminal.

Sample Requests

But here are some simpler HTTPie commands. (HTTPie is available as the http command):

# GET request to localhost:3000
http :3000/api/users

# json POST
http POST :3000/api/users name=Yada

Sample Output

❯ http POST :3000/api/users name=Yada -v
POST /api/users HTTP/1.1
Accept: application/json, */*;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-Length: 16
Content-Type: application/json
Host: localhost:3000
User-Agent: HTTPie/2.6.0

{
    "name": "Yada"
}


HTTP/1.1 200 OK
Content-Length: 497
Content-Type: application/json;charset=utf-8
Date: Tue, 19 Sep 2023 17:59:34 GMT
Server: Jetty(9.4.51.v20230217)

{
    "35c6a774-677d-4b65-8297-765b791a4ae9": {
        "id": "35c6a774-677d-4b65-8297-765b791a4ae9",
        "name": "Yada"
    },
}

Ooooooh...