The success code for creation operations in REST APIs
The HTTP 201 "Created" code indicates that the request succeeded and a new resource was created on the server. It's the appropriate response code for POST (and sometimes PUT) requests that create data. It's more precise than 200 because it explicitly informs the client that something new now exists.
In a well-designed REST API, the 201 is systematically accompanied by information to access the new resource: the Location header containing the resource URL, and often the body containing the complete representation of what was created. This rich response allows the client to continue without additional requests.
For monitoring, endpoints returning 201 are often critical: order creation, user registrations, form submissions. A 201 that stops working means your users can no longer create data. MoniTao allows you to monitor these endpoints with POST requests and verify the 201 code.
Code 201 conveys several important pieces of information to the client:
Here are typical situations where code 201 is appropriate:
Here's how to properly implement a 201 response in your API:
// PHP - Creating a user
public function createUser(Request $request): Response
{
$data = $request->getJson();
// Validation...
$user = User::create([
"name" => $data["name"],
"email" => $data["email"],
]);
return new Response(
json_encode($user),
201, // Created
[
"Content-Type" => "application/json",
"Location" => "/api/users/" . $user->id
]
);
}
// Node.js / Express
app.post("/api/users", async (req, res) => {
const user = await User.create(req.body);
res.status(201)
.location(`/api/users/${user.id}`)
.json(user);
});
Note the key elements: the 201 code, the Location header pointing to the new resource, and the body containing the complete representation with generated fields (id).
Monitoring creation endpoints is crucial for your business:
200 is a generic success. 201 is specific: it indicates a resource was created. For a POST that creates data, 201 is semantically correct and more informative.
It's not required by the HTTP spec, but it's REST best practice. The client receives the resource with its generated fields (ID, timestamps) without an additional GET request.
Return a 409 Conflict with a message explaining the conflict. Some APIs use 422 Unprocessable Entity. In any case, no 201 if creation didn't happen.
Yes, if the PUT creates the resource (upsert). If the resource already existed and was updated, use 200 or 204. 201 is reserved for creations.
Create a dedicated /api/health/create-test endpoint for monitoring that creates and immediately deletes, or use MoniTao webhooks to clean up test data.
Most frameworks allow specifying the code: response.status(201) in Express, return response(201) in Laravel, HttpResponse(status=201) in Django.
Using code 201 correctly is a sign of API maturity. It provides precise semantic information to the client: "I created something new, here's where to find it". Combined with the Location header and an informative body, it allows the client to work efficiently without additional requests.
MoniTao lets you monitor your creation endpoints with configurable POST requests. Verify that code 201 is returned, that the Location header is present, and that response time remains acceptable. A failing creation endpoint directly impacts acquisition and conversions.
Start free, no credit card required.