201 Created

A new resource was created.

When to use it

After a POST that creates something. Include a Location header pointing to it.

Good to know

Send a Location header with the URL of the new resource, and return its representation in the body if clients will need it, which saves a follow-up GET. Location may be relative; clients resolve it against the request URL. HTTP clients don’t follow Location on a 201, because it isn’t a redirect, so your code has to read the header itself.

Make creation safe to retry: a client that times out will often resend the POST and create a duplicate. Accept an Idempotency-Key header, as Stripe does, or let clients PUT to an ID they generate, and answer the repeat with the original response. Use 202 instead if the resource only exists after a background job finishes, and 409 when a unique value is already taken.

Success (2xx)

2xx codes mean success: the server received, understood and accepted the request.

What it looks like

HTTP/1.1 201 Created

How to send it

Node.js / Expressres.status(201).end()
Python / Flaskreturn '', 201
nginxreturn 201;

How to check it

curl -s -o /dev/null -w "%{http_code}\n" https://example.com/

Open HTTP Status Codes