What is a Postman? It is another popular tool for testing APIs. Postman can be used to send API requests to any REST API, and also can be used to receive responses to your requests. What is a POST Request? This happens when a client is posting data on a specific endpoint and this method is always used to send some information into the body of the request and to the server. When we send a POST request what this means is that we want to make some modification at the server level like Updating and Deleting. One good example is the sign-up process, where you are sending your details to the server for keep and for subsequent access. POST requests are always used in sending some sensitive information through the submission of a form to the server. If you want to read more on Postman with AWS you can check this: How to Use Postman with the Amazon Pinpoint API and if you want to read more on AWS Services you can check these: How to enable Amazon S3 default bucket encryption using S3 Console, How to deploy a .NET application to AWS Elastic Beanstalk using AWS Tool Kit, How to Deploy MVC Application to AWS EC2 Using RDP Connection and Web Deploy, How to Deploy Dynamic Website to AWS EC2.
In this guide, I will be showing you different features of POST Requests and how we can use them in Postman.
POST Request in Postman
If an endpoint specifies that it should be called using the POST method, then clients are mandated to call the Endpoint with a POST method. I am going to show you what happens when you use GET method instead of the POST method for a POST Endpoint and what also happens when we do POST Request without Body.
Using a GET Request on POST Endpoint on the image below pops out error for the singular reason that a GET method will not work on a POST request. The request was a login request which is a POST request.
Check the HTTP status showing 405 Method not allowed. This means that we are hitting the endpoint with incorrect method type and shows the error message “The GET method is not supported for this route. Supported methods: POST.”. The below image shows the details.
The above shows that the method type that was used is not valid and another method type is expected. Now let us change it to POST Method and see the response. You can see the response below shows a Status: 200 OK because the correct method was used this time around.
Now let us try a Login Request that uses a POST method and send without Body or try to enter wrong details into the Body, the image below shows the response 400 Bad Request and with a message showing “Validation failed” this shows that nothing was passed in the Body or incorrect details.
Now let us pass all the required login details into the body and see the response. The below response rightly show a Status: 200 OK
So the above examples clearly show that anytime we are sending a POST request, it should be accompanied by the Body and the body should be in the correct format and details for you to get a correct response from the server.
We just discussed that sending a POST request involves sending a request with required data wrapped inside the body of the request. Just as there are different types of data, there are also different ways of sending data.
But now we are going to discuss other features of Post request in Postman.
- Now select the method request type as POST in drop-down.
Immediately you select POST from the drop-down you will see that the Body is enabled with different options to send the data inside the body. These options are:
Now let me explain some of these options.
- Form Data
This feature is used to send data that you are wrapping inside the form like the information required into a form. These details are usually sent in the form of KEY and VALUE where the key is the “name” of the entry you are sending and value is its value.
Assuming you need to enter First name and Last name into the form-data, it will look like the below:
- First name: Christian
- Last name: Joshua
Here, the fields are First name and Last name while the value that will be entered into the fields are Christian and Joshua.
Both the form-data and x-www-form-urlencoded work the same way except that the URL will be encoded when x-www-form-urlencoded is used. Encoded means the data which is sent will be encoded with different characters so that if an attacker bypassed the request and get hold of the data they will not be able to recognize or understand it.
This part is mostly used when sending the body in the POST method. It can contain anything and whatever is in the text area gets sent with the request. The raw editor lets you set the formatting type along with the correct header that you should send with the raw body.
This part is designed to send data in a format that cannot be entered or written manually like image file since everything in a computer is converted to binary.
You should always know that your server is always waiting for only request it can entertain in a desired format so there is no way you can send another format than what your server is expecting, otherwise there will be no response or incorrect response as shown through the Status codes earlier.
If you have any API collection you need to use or test you can import it into your Postman and make use of it by clicking on import and select the API file and it will be imported.
I hope you found this blog post on How to use Postman for your POST Request very interesting and helpful. In case you have any questions do not hesitate to ask in the comment section.