Skip to content

201 Created — Meaning, Common Causes & How to Fix

201 2xx Success RFC 9110 §15.3.2

201 Created means: The request succeeded and a new resource was created as a result. The response should include a Location header pointing at the new resource, or at least describe it in the body; it is the canonical answer to a successful POST that creates something. Success 2xx codes confirm the request was received, understood and accepted. The family distinguishes what kind of success happened — content returned, resource created, work queued, or nothing to return — and choosing the precise code is part of a well-designed API contract that clients and caches can rely on. In practice you will meet 201 when a post creates a database record, user, order or file; a put creates a resource at a client-chosen uri that did not exist before; an api provisions a cloud resource (bucket, instance, queue) synchronously. On the client side, read the Location header (or body id) to address the new resource in follow-up calls; do not re-POST blindly or you will create duplicates. On the server side, set Location to the canonical URI of the created resource and return its representation or identifier; use 202 instead when creation is asynchronous.

Advertisement
Ad slot · ref-top

When 201 happens

  • A POST creates a database record, user, order or file
  • A PUT creates a resource at a client-chosen URI that did not exist before
  • An API provisions a cloud resource (bucket, instance, queue) synchronously

How to fix it

On the client

Read the Location header (or body id) to address the new resource in follow-up calls; do not re-POST blindly or you will create duplicates.

On the server

Set Location to the canonical URI of the created resource and return its representation or identifier; use 202 instead when creation is asynchronous.

Should you retry?

Success — do not re-POST or you may create duplicates; address the new resource via Location.

Debugging steps

When 201 appears unexpectedly, start by capturing the full exchange: 'curl -i' or the browser DevTools Network tab shows the exact status line and response headers, which often carry the real explanation. Success codes rarely need debugging, but verify the body semantics match the code — a 200 wrapping an error payload is an API design bug, not a transport problem. For this code specifically, check whether the most common trigger applies to your situation: a post creates a database record, user, order or file. Compare your exchange against the raw HTTP example above. If you operate the server, correlate the timestamp with application and proxy logs using the request id; if you are the client, verify the request shape against the API documentation before changing anything or retrying.

Notes & gotchas

A 201 without Location or a body identifier leaves clients unable to address what they just created — always return a canonical URI for the new resource.

Examples

Raw HTTP
HTTP/1.1 201 Created
Location: /api/orders/12345
Content-Type: application/json
Content-Length: 75

{
  "id": 12345,
  "status": "ok",
  "message": "Created example payload"
}
curl
curl -i https://api.example.com/v1/resource   # observe the 201 response and its headers
JavaScript (fetch)
const res = await fetch("https://api.example.com/v1/resource");
if (res.ok) {
  const data = await res.json(); // 201 Created
  return data;
}
Python (requests)
import requests

res = requests.get("https://api.example.com/v1/resource", timeout=10)
res.raise_for_status()
data = res.json()  # 201 Created

Frequently asked questions

Is Location mandatory with 201?

RFC 9110 says the origin server SHOULD send Location, or describe the resource in the body. Returning neither leaves clients unable to address what they created.

When should I use 201 vs 200 for POST?

201 when a new resource exists afterwards; 200 when the POST just performed an action or returned a computation result.

Which 2xx code should my API return?

200 for a normal result, 201 when a resource was created (with Location), 202 when work is queued, 204 when there is nothing to return. Precision here makes clients, caches and monitors behave correctly.

Can I treat any 2xx as interchangeable success?

For 'did it work' yes, but the distinctions matter operationally: 201 means a resource exists, 202 means work is still pending, 204 means there is no body to parse. Code that ignores them breaks.

Advertisement
Ad slot · ref-in-article

Try the JSON Validator

Check JSON syntax and locate errors by line and column.

Open tool →