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:
- Not cached unless specified
- Not saved in browser history
- Cannot be bookmarked
- No restrictions on data length
- More secure than GET for sensitive data
- Used to submit data to be processed
How to Make a POST Request
Using our Postboy, follow these steps to make a POST request:
- Select
POSTfrom the method dropdown - Enter the URL you want to post data to
- Go to the "Body" tab to add your request data
- 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
- Add headers in the "Headers" tab (e.g., Content-Type)
- 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
POST https://jsonplaceholder.typicode.com/posts HTTP/1.1
Host: jsonplaceholder.typicode.com
Content-Type: application/json
{
"title": "foo",
"body": "bar",
"userId": 1
}
Response:
{
"title": "foo",
"body": "bar",
"userId": 1,
"id": 101
}
Example 2: POST with Form-Urlencoded Data
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):
{
"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)
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):
{
"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
- 200 OK - The request has succeeded
- 201 Created - The request has succeeded and a new resource has been created
- 400 Bad Request - The server couldn't understand the request
- 401 Unauthorized - Authentication is required and has failed or not been provided
- 403 Forbidden - The client does not have access rights to the content
- 404 Not Found - The server can't find the requested resource
- 409 Conflict - The request conflicts with the current state of the server
- 422 Unprocessable Entity - The request was well-formed but unable to be followed due to semantic errors
- 500 Internal Server Error - The server encountered an unexpected condition
Try It in JavaScript
Here's how you can make a POST request in JavaScript:
JavaScript Example
// 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();