What Is Postman - Everyday Usages
In this post you will learn what is Postman and why I think that it is the best tool to test your API.
Among web developers I see 2 different types of people. First group doesn't know how to test their API and they just setup some client with Javascript inside React application to check how API requests are working. This is not efficient.
Other group is more advanced and they simply use CURL inside console to make requests. This is totally possible but it is not comfortable.
This is why I highly recommend to look on the Postman tool which is the most popular solution to make and test API requests.
What is Postman
Here I'm in the official website of Postman. On the top you can see pricing tab. Which actually means it is not only a free product. There are paid tiers but I never used them and you don't need them for everyday usage of Postman.
Most importantly Postman works on any operational system and this is how it looks like.
As you can see this is a standalone application where we can make HTTP requests. For this post I want to use an API from https://angular.realworld.io/ project which include anonymous and authorized requests.
To get a list of article we can use
https://conduit.productionready.io/api/articles?limit=10&offset=0
Now we can simply jump inside Postman and put this URL inside. Additionally we must set a method to GET.
After we click on the Send button on the bottom we see the whole request from the API. So we have our object with field articles
and it is an array with information. Also we can see that our request was 200
History
Another cool thing that I like about Postman is history by default.
As you can see on the left we I activated History tab. Now I have all requests that I made previously there. I can just click on any of them and it will just to the same request that I did previously with correct url, method and body.
Which actually means that Postman saves all requests out of the box and it is extremely comfortable.
Passing body
Another typical thing that you will do with Postman is obviously using body. For example in angular.realworld.io we have a sign up. It is a POST request with email, username and password.
Here I activated body
tab on the right and selected raw
. As we typically work with JSON it makes a lot of sense to highligh JSON syntax and it will highlight errors for us.
We provided a body of the request and when we hit Send
we successfully created a user.
But it is not all. As you can see we got an authorization token back in the response. It allows us to use this token later for authenticated requests.
Headers
In order to authorize a request we must provide a header to the request. For this we have a separate tab Headers
. This particular API waits from us header Authorization
with the correct token. Let's try to make an authenticated request and get a feed of just registered user.
The url to get a feed is
https://conduit.productionready.io/api/articles?favorited=bfdbdffbfdb&limit=10&offset=0
Here we provided an Authorization header and put inside a token that we got from registration. As you can see we got an empty array of articles back. It is because our fresh user doesn't follow anybody. But we didn't get 401 so our code it working correctly.
Collections
And the last thing that I want to show you in Postman are collections. The are available even on the free tier.
Collection is a folder to group your requests.
When we work on specific API we can store all requests with good naming inside a collection. It allows us to manage requests easier.
As you can see I have several collections. I just created collection Foo
. Now on any request we can click Save as
and select our collection. Also we can provide a name of the request to understand what is it about.
Want to conquer your next JavaScript interview? Download my FREE PDF - Pass Your JS Interview with Confidence and start preparing for success today!