POST request with Postman
In previous tutorials we learned how to send aGET requestand we learn about them toorequest parameters🇧🇷 From our resting basics we already know what aHTTP requesteHTTP responseIf you haven't read these two tutorials yet, please do so before proceeding. In this chapter, we'll focus on another type of query method, vizPOST request in Postman.
What is a POST request?
ONETO POSTIt is aVerbo-HTTPsimilar to aTAKE ITRequest, this indicates that a client is sending data to the givenPoint🇧🇷 ONETO POSTrequest is a method used when we need to send some additional information to the server inside the request body. Usually, when we send a POST request, we intend to make some changes on the server, e.gupdate, delete or add.One of the classic examples of a POST request is the login page. When you first sign up for something, say Facebook, you send your personal information, like a password, to the server. The server creates a new account with the same data and this account is permanently added to the Facebook server.You just created a new resource on the server.TO POSTRequests are very popular and are mainly used when you are submitting sensitive information, e.g. B. when submitting a form or when sending sensitive information to the server.
In this tutorial we will explore different features ofTO POST requests fromand how can we create them in Postman. Before we try to use an example to get a clear idea of aTO POST inquiry.
POST request in Postman
EveryoneClamp RESThas his ownVerb HTTPassociated with her. If an endpoint specifies that it should be invoked using the POST HTTP verb, clients must also invoke the endpointVerbo POST HTTPonly. First, let's check what happens when we request themTAKE ITmethod insteadTO POSTmethod for aTerminal-POST🇧🇷 Also to check what happens when we do itTO POSTinquirywhichBody.
GET request on POST endpoint
- Use APIhttp://restapi.demoqa.com/customer/register(This API is used to register a new customer)at the bar endpoint Postman and pressFrom you🇧🇷 Make sure thatTAKE ITis selected from the Method Type drop-down list.
- Look at the HTTP status code, it will be405 method not allowed.This means we're reaching the endpoint with the wrong method type. The picture below shows the details.
- See the answer belowBodyTab and focus onerror error.
This means that the method type we are using is not valid and a different method type is expected. So let's try to change that and see if we get the right answer.
POST request with no body
- Change the method type toTO POSTand pressureFROM YOU
- Now look at thoseresponse bodyeresponse status code.
Invalid post request errormeans that theThe shipping details we entered are invalid🇧🇷 Remember that we put the information in the request body, so we need to put something in the request body and see if this format matches the expected format. Also, you can see the status code that saysOrder 400 BAD🇧🇷 This means that the request parameters do not match the server parameters to get a response.
Postanfrage in Postman
- Now let's add oneRequestBodyto our POST request. Each endpoint is documented with the expected method type and text format. Let's see what text this request expects and how to add it. To do this, click onBodyab.
- Click Raw and choose format type likeJSON, since we need to send the wrong format that the server expects.
- This endpoint expects ajsonbody containing the new user's details. Below is an examplejsonBody. Copy and paste the following into the Postman tab.
*"Last Name: "Value",*
change the attributebraveryto the desired value (refer to the picture below).
- PressFrom youand see theresponse bodyeresponse state.
The mistakeThe failed user is already terminatedmeans that a similar entry has already been created in the database by you or someone else before. While when you see that theresponse statusIt is200 OK,which means the server accepted the request and sent a successful response. From this we can also conclude that the response body was correct and the server was able to interpret the response body. Now in this API request, the email address and username must be unique. Then you can change these values (everyone will work too).
If the values are unique, you will get this response
Operation completed successfullymeans your input wassuccessfully created in the database.
So from this example it is clear that whenever we need to send aPOST request, must be accompanied by the Corps. The body must be in the correct format and with the correct curly braces in order to get a correct response from the server. Now we will learn in detail about each function of post request in Postman.
Different ways to send the data in a POST request in Postman
As we have already discussed, sending a POST request means sending a request with the data included in the body of the request. There can be different types of data and likewise there are different ways of sending data. You can learn more about it by following these steps.
- Select the method request type asTO POSTin the constructor as shown.
Once you select the POST request type in Postman, you will see that the Body option is checked, which has different options for sending the data inside the body. These options are:
- form data
Form data, as the name suggests, is used to submit the data you collect within the form, e.g. B. details entered when filling out a form. These details are sent by sending asKEY VALUECouples where the key "Name" of the input you are sending and the value is the samebravery🇧🇷 The following steps will make that clear.
1. Dialform data
- add the followingKEY VALUEPar
- first name: Harish
- Surname: Rajora
Here is somehow the first name in the field (text box here) that you need to enter andHarishis its value, i. H. the value that the user entered. The same applies to the surname ID.
form dataex-www-form-urlencodedThey are very similar. Both are used for almost the same purposes. But the difference between form data andx-www-form-urlencodedis that the URL is sent encrypted viax-www-form-urlencoded🇧🇷 Encrypted means that the data sent is encrypted in different characters, so that it is not detectable even if attacked.
Raw is the most used part or option when sending text in POST method. It is important from the postman's point of view. Raw means that the main message is displayed as a stream of bits that represent the body of the request. These bits are interpreted as a string server.
- Click on the drop down menu next to itbinaryand you will see all the options where you can send the request
- click inJSON (application/json)
- Copy and paste this into the editor below
"First Name": "Harish",
"last name": "Rajora"
This is the same data that was previously submitted with form data, but is now submitted in JSON format.
Binary is designed to send the information in a format that cannot be typed in manually. Since everything on a computer is converted into binary files, we use options that cannot be written by hand, such as an image, a file, etc.
- click inbinary, oneSELECT FILESoption will be available
- Choose any file, e.g. B. an image file.
monitoringNote: If you want to send data to the server along with the file, you can also do this in the data form.
click noform data
Inputarchivelike a key
and you will see a hidden dropdown menu with text as default. You can choose any file format and then choose the system file.
Always remember what your server is waiting for. You cannot send any format other than what your server expects, otherwise there will be no response or an incorrect response, which is evident from the response status code. Now we have learned about the POST method and how to use it in Postman. We will now move on to the next tutorial, that iscollections.
There are other types of REST requests. If you want to learn more about it, watch the following videos:
PUT request in postman
DELETE request in Postman