in XML by
How to create POST Request in Postman?

1 Answer

0 votes
by
edited by

The post is an HTTP method like GET. We use this method when additional information needs to be sent to the server inside the body of the request. In general, when we submit a POST request, we expect to have some change on the server, such as updating, removing or inserting.

One of the best examples of using POST request is the login page of Facebook or the login page of other sites; you send your personal information such as the password to the server. The server creates a new account with the same information and that account, and the information is added permanently on the Facebook server.

The POST request is a fundamental method, and this method is mostly used when a user wants to send some sensitive data to the server like to send a form or some confidential data.

Important points of the POST request:

  • POST requests will not take the cookies.
  • POST requests are not left in the history of browsers.
  • We cannot bookmark the POST requests.
  • There is no restriction of data length in POST requests.

In Postman, every endpoint of REST API is associated with its HTTP verb. When an endpoint states that it should be called using the POST http verb, then for calling the endpoint, only the POST HTTP Verb is required.

Let's first check with the GET request for a POST endpoint.

GET Request on POST Endpoint

Here, we have one API which is used to register a new customer:

http://restapi.demoqa.com/customer/register

Enter the URL in the postman endpoint bar, and press Send. Then select the GET method from the drop-down list.

POST Request in Postman

See the following response:

POST Request in Postman

See the HTTP status code, and you will get the "405 Method Not Allowed" error code. It means we are requested for an endpoint with the wrong method. And in the Pretty tab also you can see the fault error.

POST Request in Postman

This means we selected the incorrect method type. Now let's try to change the type of method and see if we will get the right response.

Post Request without Body

First, change the type of method from GET to POST and click on the Send button.

POST Request in Postman

Now, see the response section.

POST Request in Postman

Here, 400 Bad Request, as shown in the image above, indicates that the request and server parameters are not found matched to get a response. And from the response body, 'Invalid post data' means the entered post data is not valid.

So, we are required to add the information with the correct format within the request body.

Adding a Request body to the Post request- For this, select the Body tab.

POST Request in Postman

Now in the Body tab, select raw and select JSON as the format type from the drop-down menu, as shown in the image below. This is done because we need to send the request in the appropriate format that the server expects.

POST Request in Postman

In my example, server expects a json body that contains new user information. Here is one simple example:

  1. {  
  2.    "FirstName"  : "value",  
  3.    "LastName"  : "value",  
  4.    "UserName" : "value",  
  5.    "Password"  : "value",  
...