A more minimal way to test API routes

#api#rust#cli#testing#rewrite::alemi::2023-05-21 18:35

postwoman

I have seen postman used in a lot of places and by a lot of people, but I've never really understood it. Wouldn't I be better off using curl and maybe scripting some requests from the terminal? Why would I need to download a dedicated software for that? Also electron isn't exactly lightweight, so I've always steered away.

My current job at the time however put a lot of emphasis on testing, and introduced me to test-heavy workflows. At that point I saw postman usefulness: most value comes from the underlying collection! Developers share one and added routes they would work on. Once we had tested our code "from the inside" with unit and integration tests, we would send it to staging and test if "from the outside", running all requests in the postman collection.

This is great! However newer postman versions require me to register an account to be able to use the collection features, and once you're logged in, everything is kept in sync with their servers automatically.

This is awful! Why would you do that! I could not find an option to disable such feature at the time, and it was a huge dealbreaker: we can't have company internal structure and tokens just sitting on postman servers like that. What the hell!

So I decided to write my own solution. The collection format is just a json file, with proper documentation. Making requests is easy enough. Loading secrets can be done from the shell environment. And just like that, the first version of postwoman was born! Why postwoman? Because we need more women in tech (:

I eventually found a rust library handling postman collection deserialization, so I could focus on running all tests.

This doesn't provide all features postman supports, only a subset is actually used, and it's not scriptable due to the weird print format. But it works, if you have a simple collection and would rather not use postman, consider using postwoman! If it doesn't do what you need, send a PR my way!

source code