Python Friday #31: HTTPie as a Curl Replacement

If you work with a REST API, you may use curl to explore the various actions. The Python project HTTPie is a user-friendly replacement with a much clearer syntax.

This post is part of my journey to learn Python. You can find the other parts of this series here.

 

Installing HTTPie

HTTPie is an HTTP client you can use to explore (web) APIs. It comes with a great documentation, supports JSON, offers syntax highlighting and understands sessions. It works with everything that supports HTTP and not just applications written in Python.

You can install HTTPie using pip. It is such a great help that you may install HTTPie into your global Python installation and not just into a virtual environment:

 

http or https?

HTTPie comes with to executables: http and https. The http command uses the default scheme HTTP, while https uses HTTPS. Depending on what you need more, using the right executable can save you a lot of typing.

 

Common use-cases

You can fetch the HTML of a web site by entering the URL of that site:

To get only the headers of your request and the response, you can use the option –print=Hh:

You can send cookies as a string with the format 'Cookie:key=value':

You can check if a specific SSL/TLS version is supported on your web server (if not, you get something like this output:

Those examples are just the tip of the iceberg. There are many more options you can use to get from HTTPie exactly the request you want. The more you use this tool, the more you are going to like it.

 

Conclusion

I find HTTPie a great addition to my tool list. It offers many options to explore an HTTP API and the syntax highlighting ensures that you spot the important parts.

3 thoughts on “Python Friday #31: HTTPie as a Curl Replacement”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.