Skip to content

How To Send A Post Request Using Postman

API Testing Blog

Sending POST Requests with Postman: A Beginner’s Guide

Postman is a powerful tool for API testing, allowing you to send various types of HTTP requests, including POST requests. POST requests are used to send data to a server to create or update resources. Here’s a comprehensive guide on how to send POST requests using Postman:

1. Creating a POST Request in Postman

  • Open Postman: Launch the Postman app or visit the Postman website.
  • Create a New Request: Click on the “New” button or press Ctrl+N to create a new request.
  • Choose POST Method: In the “Method” dropdown, select “POST.”

2. Setting the Request URL

  • Enter the URL: In the “Enter request URL” field, type the URL of the API endpoint you want to send the request to.
  • Example: For a simple example, you can use the https://reqres.in/api/users endpoint from the Reqres API. This API allows you to create new user entries.

3. Adding Request Parameters

  • Body: Click on the “Body” tab in the Postman request window.
  • Select the Body Type: Postman offers several body types. Choose the most suitable one for your API:
    • form-data: For sending form-encoded data (key-value pairs).
    • x-www-form-urlencoded: For sending data in a similar way to form-data.
    • raw: For sending plain text, JSON, or other raw data.
    • binary: For sending binary files.
  • Enter the Parameters: Add the required parameters and their values. For example, if you’re sending user information, you might have parameters such as name, job, etc.

Example:

{
"name": "Test User",
"job": "Tester"
}

4. Sending the POST Request

  • Click the “Send” button: This will execute your POST request and send the data to the server.

5. Viewing the Response

  • Response Body: Postman will display the response from the server in the “Body” section. This includes the data returned by the API.
  • Response Headers: You can view the response headers in the “Headers” section. This includes information such as the content type, status code, and more.
  • Response Status Code: The “Status Code” in the top right corner indicates the success or failure of the request. 200, 201, and 202 indicate success, while other codes might indicate errors or failures.

6. Understanding POST Request Parameters

  • Headers: Headers are used to provide additional information about the request, such as the content type of the body. You can set headers in the “Headers” tab.
  • Authorization: You can set authorization for the request in the “Authorization” tab. This is commonly used to authenticate against an API.

7. Additional Tips

  • Save Your Requests: Save your requests as collections or environments for easy access and reuse.
  • Use Variables: Define variables for reusable values like URLs and API keys, making your requests more dynamic.
  • Testing and Debugging: Use Postman’s tools for testing, debugging, and validating responses.

8. Examples with Code

Example 1: Creating a User with Reqres API

  • URL: https://reqres.in/api/users
  • Method: POST
  • Body: raw

Body Data:

{
"name": "Test User",
"job": "Tester"
}
  • Send the request. You should get a successful response (status code 201) with the newly created user details.

Example 2: Update a User’s Profile

  • URL: https://reqres.in/api/users/2
  • Method: POST
  • Body: raw

Body Data:

{
"name": "Updated User",
"job": "Software Engineer"
}
  • Send the request. You should get a successful response (status code 200) with the updated user details.

9. Conclusion

Postman is a valuable tool for sending POST requests and testing your APIs. By following this guide, you can easily create and execute POST requests, understand the different parameters and options, and effectively test your API’s functionality.

API Testing Blog