Postman was my go to tool when I considered making a http request. That all changed when I found out httpie gives a very easy and short API precisely for this. In this post I will show why I like httpie. The full documentation can be found on the httpie page.
Together with the tool that lets you scroll through your command history (as discussed in a previous post on fish shell), httpie is my new default tool to make http requests.
On my mac I typed:
brew install httpie
Say you want to make a GET request to an API you have running locally. This would be the command:
As you can see GET is the default method and you don’t even have to type localhost! The
is there to see the request that is generated and see how the response json is pretty printed.
Now we want to do something a bit more complicated. We want to POST a json body to create a product.
We can just define the properties of the json and initialise them with
. Or we can write the full json string with
. Both are used in the example above.
What if we want to do even more, like setting headers:
Just use single quotes, then name
value. It’s as easy as that. For basic auth there is an even faster notation.
As you can see it is very easy to get started with httpie. There are short notations for a lot of http building blocks. Happy http’ing!
Leave a Reply