As a Icinga 2 developer I often use the Icinga 2 REST API to test new features or debug Icinga itself. Of course most people use curl for that kind of task, and so did I.
That resulted in sometimes rewriting the same request a lot over the course of a few weeks. To counter that I just saved my most used requests into my notes which wasn’t that simple to maintain.
A few weeks ago that finally changed as I stumbled across Postman. Postman is a tool for developing, maintaining and testing REST APIs. I’d like to give you a quick rundown of its features, to show you why it has made my development life so much easier.
Requests:
Requests require, like in most HTTP clients, a method, URL, headers and maybe a body, depending on the method. But in Postman you can also add tests and pre-request scripts written in JavaScript.
Collections and folders:
All your request can be sorted into collections and folders. That allows you to have variables and tests based on your current collection/folder.
Variables:
In Postman collections and environments can have variables, if needed you can even create global variables. In the first example I used a collection variable called{{icinga-url}}
which looks like this https://{{host}}:{{port}}/v1
and itself is based on two environment variables.
Environments:
The only purpose of environments is to allow you to switch between sets of variables. You might need a URL and some credentials for a Icinga API at localhost and the same variables with different values for a customer setup.
Generate code from requests:
If you wan’t to use a request inside your software, Postman allows you to just export request as code. They provide a few common languages as seen below.
More features:
- Test requests with JavaScript
- Monitor APIs
- Mock APIs
- Generate API documentation
- Generate request code from Postman (Curl, Python, C++ and more)
- Darktheme (Most importent feature obviously)
Conclusion:
Over the last few weeks it saved me a lot of time, because I didn’t need to rebuild my requests in curl every time I needed them. And if I’ll ever build an API from scratch, this will help me for sure.
0 Kommentare
Trackbacks/Pingbacks