4. Postman guide

What is Postman ?


Postman is the world's most famous tool used for building and testing API. You can this tool to create, share, test and document APIs.

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/

Screenshot 2021-09-05 at 12.55.09 AM.png

Useful terminologies


  • What is Postman Collection?

    Postman Collection in Postman means a group of API requests. It is like arranging different api request related to app to a separate folder. And, you can create as any collection as you want in your postman application. Collection is basically used for documentation purpose of APIs.

  • What is Request ?

    Request is a call that is made to 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 Collection ?

    Similar to import collection, you can share you postman collection to your team members. Right click on collection folder and then click on "Export"

    Screenshot 2021-09-05 at 10.43.37 PM.png

Sending your first API request with Postman


There are multiple ways to make API request, but here we'll using Postman because of its simple and easy to understand GUI.

In the last modules, we learnt about what is HTTP request and request method. So, now is time to 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.

1. Making your first API Request

  • Enter the URL ( https://random.dog/woof.json). This is a random web api which return a random dog image.
  • This API accepts GET method. So, make sure you select GET from request method.
  • Hit Send and see the magic. Did you got a dog image in response ?

Screenshot 2021-09-06 at 1.12.54 AM.png

Did you see the response headers in above example ?

2. Making Post Request in Postman

Post HTTP request is made when you want to add or update some data on server. Here is step to make a post request from postman client.

  • Enter the request URL and select POST method from dropdown.
  • Switch to Body tab and select raw
  • Select JSON from dropdown, because the content type of body data is JSON.

Screenshot 2021-09-10 at 7.09.10 PM.png

Screenshot 2021-09-10 at 7.19.03 PM.png

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 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 because, we have not query parameter. Now, send a query parameter q with GitHub username as value ( as shown below)

Screenshot 2021-09-11 at 1.22.16 AM.png

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 ?

Screenshot 2021-09-11 at 1.30.10 AM.png

Want to exercise more on api request, you can use this fake API to play around HTTP request methods, endpoint, query parameter and body.