Last updated on July 8th, 2019 at 10:58 pm
As part of our API Testing series, we will see “Sending first POST request in Postman”.
First of all we need some APIs to test. There are many public APIs available which you can use for testing purpose. I will suggest you to register at below site to use free APIs for testing:
I will keep sharing links of public APIs for testing.
Above website provides you APIs for basic operations i.e. CRUD which we have already learnt in previous posts.
We have already covered about Sending GET request in Postman.
A HTTP POST method is used to create a new resource in collection of resources with a request body passed as a JSON/XML. If resource is created successfully at the end point, it returns a status code 201( Created) (Not always) and returns response body. It may return 200 (OK) and 204 (No Content) status code as well based on how it is created.
POST is not safe method as it is related to data creation. It is also not idempotent and invoking two identical POST requests will result in two different resources containing the same information with just different resource ids.
Request body contains data which is used to created a new resource. For example- You want to register a user on some portal and you need to pass your name , age and address. Here name, age and address are parameters which hold a value in a request body.
To perform a POST request below steps are performed:
- Select the “POST” in http methods drop down.
- Pass the request URI in address bar of Postman.
- Pass request body in desired format under Body tab.
- Add authorization if applicable.
- Add headers if applicable.
- Click on Send button.
URI and request body we can get from above website. In real time, developer will provide you all these details.
URI – https://gorest.co.in/public-api/users/
Above URI is used to register a new user with details provided in request body below.
Request Body in JSON:
Detailed steps to hit a POST request in Postman:
1. Select “POST” http method in drop down.
2. Pass URL for POST in address bar of Postman.
3. Click on “Body” tab and click on “raw” radio button. Select “JSON(application/json)” from the left most drop down. As we have JSON request body so we selected this option. If you have request body in other format, you need to select appropriate. Most common formats are JSON and XML. Paste JSON request body in textarea.
4. To hit POST request, you need to pass authorisation. You need to pass access token for GoREST APIs. You need to sign up and go to profile to get access token as shown below:
5. Go to “Authorization” tab and select “OAuth 2.0” in “Type” drop down. Paste copied access token in “Access Token” text box.
6. Hit the “Send” button. You can see response in “Body” tab of Response section of Postman. (Bottom part). Response in JSON format and it gives you details about registered user.
You can change format of response body by selecting desired format in drop down.
More about API Testing in upcoming posts. Stay tuned.
If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
Author: Amod Mahajan
My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning