POST Request Documentation

Learn how to make POST requests using our Postboy

What is a POST Request?

The HTTP POST method is used to send data to a server to create or update a resource. The data sent to the server with POST is stored in the request body of the HTTP request.

Key characteristics of POST requests:

How to Make a POST Request

Using our Postboy, follow these steps to make a POST request:

  1. Select POST from the method dropdown
  2. Enter the URL you want to post data to
  3. Go to the "Body" tab to add your request data
  4. Select the appropriate body format:
    • Form Data: For files and binary data
    • x-www-form-urlencoded: For form submissions
    • Raw JSON: For sending JSON data
  5. Add headers in the "Headers" tab (e.g., Content-Type)
  6. Click the "Send" button

The response will appear in the response section below.

Request Body Types

Form Data

Form data is used when you need to send files or binary data. It sets the Content-Type header to multipart/form-data and allows you to send key-value pairs as well as files.

x-www-form-urlencoded

This is the default format for HTML form submissions. It sets the Content-Type header to application/x-www-form-urlencoded and sends data as key-value pairs separated by ampersands.

Raw JSON

Raw JSON is commonly used in modern APIs. It sets the Content-Type header to application/json and sends JSON-formatted data in the request body.

Example POST Requests

Example 1: POST with JSON Body

HTTP
POST https://jsonplaceholder.typicode.com/posts HTTP/1.1
Host: jsonplaceholder.typicode.com
Content-Type: application/json

{
  "title": "foo",
  "body": "bar",
  "userId": 1
}

Response:

JSON
{
  "title": "foo",
  "body": "bar",
  "userId": 1,
  "id": 101
}

Example 2: POST with Form-Urlencoded Data

HTTP
POST https://postman-echo.com/post HTTP/1.1
Host: postman-echo.com
Content-Type: application/x-www-form-urlencoded

name=John&age=25&city=New%20York

Response (truncated):

JSON
{
  "args": {},
  "data": "",
  "files": {},
  "form": {
    "name": "John",
    "age": "25",
    "city": "New York"
  },
  "headers": {
    "x-forwarded-proto": "https",
    "host": "postman-echo.com",
    "content-length": "31",
    "content-type": "application/x-www-form-urlencoded"
  },
  "json": null,
  "url": "https://postman-echo.com/post"
}

Example 3: POST with Form Data (Multipart)

HTTP
POST https://postman-echo.com/post HTTP/1.1
Host: postman-echo.com
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="name"

John
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="age"

25
------WebKitFormBoundary7MA4YWxkTrZu0gW--

Response (truncated):

JSON
{
  "args": {},
  "data": {},
  "files": {},
  "form": {
    "name": "John",
    "age": "25"
  },
  "headers": {
    "x-forwarded-proto": "https",
    "host": "postman-echo.com",
    "content-length": "258",
    "content-type": "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
  },
  "json": null,
  "url": "https://postman-echo.com/post"
}

Common HTTP Status Codes for POST Requests

Try It in JavaScript

Here's how you can make a POST request in JavaScript:

JavaScript Example

JavaScript
// Using fetch API with JSON data
fetch('https://jsonplaceholder.typicode.com/posts', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    title: 'foo',
    body: 'bar',
    userId: 1
  })
})
.then(response => {
  if (!response.ok) {
    throw new Error('Network response was not ok');
  }
  return response.json();
})
.then(data => console.log(data))
.catch(error => console.error('Error:', error));

// Using async/await with form data
async function postFormData() {
  try {
    const formData = new FormData();
    formData.append('name', 'John');
    formData.append('age', '25');
    
    const response = await fetch('https://postman-echo.com/post', {
      method: 'POST',
      body: formData
    });
    
    if (!response.ok) {
      throw new Error('Network response was not ok');
    }
    
    const data = await response.json();
    console.log(data);
  } catch (error) {
    console.error('Error:', error);
  }
}

postFormData();