5. Postman guide
1. What is Postman ?
Postman is the world's most famous tool used for building and testing APIs. You can use this tool to create, share, test and document APIs.
1.1 Installation
Before we move further, (we will be making our first API request with Postman), I would suggest you to download the Postman app or you can even download the Postman chrome extension.
Download Link - https://www.postman.com/downloads/
1.2 Useful terminologies
What is Postman Collection?
Postman Collection is a group of API requests. It is like arranging different API request related to a app in a folder. You can create as many collection as you want in your Postman application. Collection is basically used for documentation of APIs.
What is Request?
Request is a call that is made to the web server to recieve or send data from a data source. APIs run on web servers, and expose endpoints to support the operations client applications use to provide their functionality.
How to import postman collection?
When you are working in a team, you will often need to collaborate on a project. When you want to use or test others Postman collection, you can simply import their collection into your app.
Steps to import Collection
- Click on the "Import" button
- Choose the source from where you want to import.
How to share Collections?
Similar to import collection, you can share you Postman collection to your team members. Right click on the collection folder and then click on "Export".
2. Sending your first API request with Postman
There are multiple ways to make an API request, but here we'll using Postman because of its simple and easy to understand GUI.
In the last modules, we learnt what is HTTP request and request method. So, now let's see it in action.
GET
Ā methods retrieve data from an API.POST
Ā sends new data to an API.PATCH
Ā andĀPUT
Ā methods update existing data.DELETE
Ā removes existing data.
2.1 Making your first API Request
- Enter the URL ( https://random.dog/woof.json). This is a random web API which returns a random dog image.
- This API accepts
GET
method. So, make sure you selectGET
as request method. - Hit Send and see the magic. Did you get a dog image in response?
Did you see the response headers in above example?
2.2 Making POST Request in Postman
Post
HTTP request is made when you want to add or update some data on the server. Here is step to make a POST request from postman client.
- Enter the request URL and select POST method from the dropdown.
- Switch to
Body
tab and selectraw
- Select JSON from dropdown, because the content type of the body data is JSON.
Curl request
curl --location --request POST 'https://reqres.in/api/users' \--header 'Content-Type: application/json' \--data-raw '{"name": "deepak12","job": "Engineer"}'
3. Making GET Request with Params and Headers
Query parameter are used when you want to filter response based on section or field. Here, we will see an example of Github Search API to demonstrate how to use query parameter in a API request.
Use GET
method and send a request on this URL. What response did you get?
https://api.github.com/search/users
Huhh, Looks like an error with Status Code 422(Unprocessable Entity)!
It return an error response as we haven't passed a query parameter. Now, send a query parameter q
with GitHub username as value (as shown below)
Also, don't forget to check the HTTP response header. The response header starting with X-
are custom headers.
Trivia time š”
Can you find out what does `Rate-Limit` and `Rate-Limit-Remaining` header does?
Want to do more API requests? You can use this fake API to play around HTTP request methods, endpoints, query parameter and body.