Create Post
Create a new post by sending a POST request with the required fields.
POST https://jsonplaceholder.typicode.com/posts
Request Body Fields
| Name | Type | Required | Description |
|---|---|---|---|
| title | string | Yes | Title of the post |
| body | string | Yes | Content of the post |
| userId | number | Yes | ID of the user |
Example Requests
- cURL
- JavaScript (fetch)
- Python (requests)
curl -X POST https://jsonplaceholder.typicode.com/posts \
-H "Content-Type: application/json" \
-d '{
"title": "foo",
"body": "bar",
"userId": 1
}'
fetch("https://jsonplaceholder.typicode.com/posts", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
title: "foo",
body: "bar",
userId: 1
})
})
.then(res => res.json())
.then(data => console.log(data));
import requests
response = requests.post(
"https://jsonplaceholder.typicode.com/posts",
json={
"title": "foo",
"body": "bar",
"userId": 1
}
)
print(response.json())
Successful Response
{
"title": "foo",
"body": "bar",
"userId": 1,
"id": 101
}
Error Responses
| Status Code | Description |
|---|---|
| 400 | Invalid request body |
| 500 | Internal server |