🎉
201
Created

Example HTTP Response

HTTP Response
HTTP/1.1 201 Created
Location: /users/123
Content-Type: application/json

{"id": 123, "created": true}
Common Causes
  • Successfully created a new user account
  • Posted a new blog article
  • Uploaded a new file
Technical Details

What does this mean?

It's alive! You asked to create something new, and voilà — it now exists in the world!

Technical Definition

The request succeeded and a new resource was created as a result.

RFC Says

"The 201 (Created) status code indicates that the request has been fulfilled and has resulted in one or more new resources being created. The primary resource created by the request is identified by either a Location header field in the response or, if no Location field is received, by the effective request URI."

Plain English:

201 means 'I successfully created the new resource you requested!' The response should include a Location header pointing to the URL of the newly created resource.

Common Misinterpretation

Don't use 200 when creating resources - use 201 instead. The Location header helps clients know where to find the newly created resource without having to parse the response body.

Code Snippets

Ready-to-use code for returning this HTTP status in your application:

Node.js
// Express.js
app.get('/example', (req, res) => {
  res.status(201).json({
    error: 'Created',
    message: 'Your error message here'
  });
});

// Native HTTP
const http = require('http');

http.createServer((req, res) => {
  res.writeHead(201, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify({
    error: 'Created',
    message: 'Your error message here'
  }));
}).listen(3000);