Testing Your API’s Using Postman

Kelvin
4 min readSep 18, 2017

--

API’s are becoming more important as technology progresses. Every device is going “smart” and connectivity between our devices is becoming more vital.

Connected devices will communicate with a server over the internet more often than not. When interactions like this happen, it’s important to understand that these devices do not communicate with servers over a graphical web page the way humans do. This makes API testing very tricky. Traditionally, we would test a website or mobile application manually by interacting with the UI components. This seems like a reasonable way to conduct tests as that’s how users will interact with the server, right? Well, not exactly. The problem with this type of testing is that it’s slow and time consuming, it takes a while to complete satisfactory tests and this method doesn’t work when testing a web service that is meant to cater to devices that do not typically use graphical interfaces to communicate over the internet such as robots or stoves.

These devices tend to communicate with servers by sending a request with data to the server and then receiving raw data from the server and processing it. If we want to test this process and make sure it’s running as efficiently as it should be, we will have to use testing methods that mimic that interaction. This is where headless testing comes into play.

Headless Testing

Headless testing is a method of testing a web service without interacting with the GUI. All web interactions over the web happen over requests to a server and responses from the server to the client. Browser add a layer of abstraction in this process so that the user doesn’t have to manually type in API calls. The GUI also helps present the information returned by the server in a manner that is more easily understood by the user. Understanding this, we can simulate this interaction more efficiently by bypassing the GUI layer altogether. This is what headless testing allows us to do, test the responses from our server by allowing us to configure requests and send them directly to the server and receive a response.

Why is Headless Testing Useful

We have already outlined some of the problems that arise from manual UI testing. Headless testing allows us to get around these problems. You can configure as many request as possible and automate API calls so that you can have maximum coverage and feedback in minimal time. This method also helps to simulate load on the server as we do not have to manually create multiple clients to make simultaneous API calls. With headless testing, you can run as many API calls as needed. This is useful for testing as it allows you to get immediate feedback on your server performance, bugs in your back-end code, or whether the latest changes have been successfully integrated into the system.

Performing Headless Testing

There are many tools designed to help you carry out headless testing on your API all designed for different needs and tastes. You can even write your own scripts that generate data and use it in requests on your API. My personal favourite method of performing headless testing is using a UI tool called Postman. Postman allows you to run requests and get responses from an API without having to open your browser or building an application to request an API. Here is what you will see upon opening Postman:

The user interface is straight forward. You choose the request method, enter the URL and the params. You may specify the authentication method if required. Once you’ve done that, click “Send” and wait to view the response in the response panel. Postman logs your previous requests and responses so you don’t have to retype requests. It even allows you to run tests on your responses which is a very important part of the headless testing if you’re aiming to automate as much as possible.

Final Words

As technology becomes more reliant on API’s and server communication, it is becoming more important for us to develop and test API’s in order to make this advancement possible. It is no longer an option as not only are smart objects of the future reliant on this functionality, but current mobile and web applications as well which are becoming more widespread. In the next post, I will be demonstrating how to create a basic API using PHP and the Slim framework.

If you’re interested in more content from me, visit my personal blog. If you are interested in acquiring my services, visit my personal website and feel free to contact me.

--

--

Kelvin

Full-stack software developer. #WebDev #Programming