Create a post
POST
https://api.testingapis.com/api/PostsRequest body
Optional. application/json, text/json, application/*+json, application/xml, text/xml, application/*+xml. Model: Post. The new post. Any client-supplied ID is replaced.
Example body
{
"userId": 101,
"title": "Getting Started with REST APIs",
"body": "REST APIs are the backbone of modern web applications. In this post, we'll cover the basics of HTTP methods, status codes, and request/resp…",
"tags": ["api", "tutorial", "beginner"],
"publishedAt": "2025-07-01T14:00:00Z",
"likes": 42
}Responses
- 200
- OK
- 201
- Created; returns { message, data } with the generated ID.
- 400
- title is missing.
- 500
- Unexpected server error.
Example
Request
curl -X POST "https://api.testingapis.com/api/Posts" \
-H "Content-Type: application/json" \
-d '{"userId": 101, "title": "Getting Started with REST APIs", "body": "REST APIs are the backbone of modern web applications. In this post, we'\''ll cover the basics of HTTP methods, status codes, and request/resp…", "tags": ["api", "tutorial", "beginner"], "publishedAt": "2025-07-01T14:00:00Z", "likes": 42}'Response201 Created
{
"message": "Post created successfully",
"data": {
"id": 19,
"userId": 101,
"title": "Getting Started with REST APIs",
"body": "REST APIs are the backbone of modern web applications. In this post, we'll cover the basics of HTTP methods, status codes, and request/re…
"tags": ["api", "tutorial", "beginner"],
"publishedAt": "2025-07-01T14:00:00Z",
"likes: 42
}
}Code examples
JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/Posts", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: "{\"userId\": 101, \"title\": \"Getting Started with REST APIs\", \"body\": \"REST APIs are the backbone of modern web applications. In this post, we'll cover the basics of HTTP methods, status codes, and request/resp…\", \"tags\": [\"api\", \"tutorial\", \"beginner\"], \"publishedAt\": \"2025-07-01T14:00:00Z\", \"likes\": 42}",
});
console.log(response.status, await response.text());Python (requests)
import requests
response = requests.request(
"POST",
"https://api.testingapis.com/api/Posts",
headers={
"Content-Type": "application/json",
},
data="{\"userId\": 101, \"title\": \"Getting Started with REST APIs\", \"body\": \"REST APIs are the backbone of modern web applications. In this post, we'll cover the basics of HTTP methods, status codes, and request/resp…\", \"tags\": [\"api\", \"tutorial\", \"beginner\"], \"publishedAt\": \"2025-07-01T14:00:00Z\", \"likes\": 42}".encode("utf-8"),
allow_redirects=False,
)
print(response.status_code, response.text)Java (HttpClient)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newBuilder()
.followRedirects(HttpClient.Redirect.NEVER)
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.testingapis.com/api/Posts"))
.header("Content-Type", "application/json")
.method("POST", HttpRequest.BodyPublishers.ofString("{\"userId\": 101, \"title\": \"Getting Started with REST APIs\", \"body\": \"REST APIs are the backbone of modern web applications. In this post, we'll cover the basics of HTTP methods, status codes, and request/resp…\", \"tags\": [\"api\", \"tutorial\", \"beginner\"], \"publishedAt\": \"2025-07-01T14:00:00Z\", \"likes\": 42}"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode() + " " + response.body());
}
}