How to make a POST request in Postman (2023)

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
  1. 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.

How to make a POST request in Postman (1)

  1. 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.

How to make a POST request in Postman (2)

  1. See the answer belowBodyTab and focus onerror error.

How to make a POST request in Postman (3)

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
  1. Change the method type toTO POSTand pressureFROM YOU

How to make a POST request in Postman (4)

  1. Now look at thoseresponse bodyeresponse status code.

How to make a POST request in Postman (5)

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
  1. 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.

How to make a POST request in Postman (6)

  1. Click Raw and choose format type likeJSON, since we need to send the wrong format that the server expects.

How to make a POST request in Postman (7)

  1. This endpoint expects ajsonbody containing the new user's details. Below is an examplejsonBody. Copy and paste the following into the Postman tab.

{

*"name": "value"*

*"Last Name: "Value",*

"Username: "value",

"password": "value",

"email": "value"

}

change the attributebraveryto the desired value (refer to the picture below).

How to make a POST request in Postman (8)

  1. PressFrom youand see theresponse bodyeresponse state.

How to make a POST request in Postman (9)

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

How to make a POST request in Postman (10)

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.

  1. Select the method request type asTO POSTin the constructor as shown.

How to make a POST request in Postman (11)

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
  • X-www-form-url-encoded
  • Cru
  • Binary

How to make a POST request in Postman (12)

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

How to make a POST request in Postman (13)

  1. add the followingKEY VALUEPar
  • first name: Harish
  • Surname: Rajora

How to make a POST request in Postman (14)

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.

x-www-form-urlencoded

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.

How to make a POST request in Postman (15)

Cru

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.

  1. Click on the drop down menu next to itbinaryand you will see all the options where you can send the request

How to make a POST request in Postman (16)

  1. click inJSON (application/json)

How to make a POST request in Postman (17)

  1. Copy and paste this into the editor below

{

"First Name": "Harish",

"last name": "Rajora"

}

How to make a POST request in Postman (18)

This is the same data that was previously submitted with form data, but is now submitted in JSON format.

Binary

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.

  1. click inbinary, oneSELECT FILESoption will be available

How to make a POST request in Postman (19)

  1. Choose any file, e.g. B. an image file.

How to make a POST request in Postman (20)

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

How to make a POST request in Postman (21)

Inputarchivelike a key

How to make a POST request in Postman (22)

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

References

Top Articles
Latest Posts
Article information

Author: Kareem Mueller DO

Last Updated: 30/08/2023

Views: 6474

Rating: 4.6 / 5 (46 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Kareem Mueller DO

Birthday: 1997-01-04

Address: Apt. 156 12935 Runolfsdottir Mission, Greenfort, MN 74384-6749

Phone: +16704982844747

Job: Corporate Administration Planner

Hobby: Mountain biking, Jewelry making, Stone skipping, Lacemaking, Knife making, Scrapbooking, Letterboxing

Introduction: My name is Kareem Mueller DO, I am a vivacious, super, thoughtful, excited, handsome, beautiful, combative person who loves writing and wants to share my knowledge and understanding with you.