201

Created

2xx Success

Back to list

Server perspective

Use 201 when the request succeeded and created a new resource.

When to use

  • Return 201 after POST creates a resource
  • Use it for PUT when the target URI did not exist and the request created it

How to respond

  • Include a Location header when it helps identify the newly created resource
  • Return a representation of the created resource when that makes the API easier to use

Headers to consider

  • Location
  • ETag

Response body

  • Optionally include the created resource or creation result in the response body

Server-side pitfalls

  • Do not use 201 for ordinary updates that did not create anything new
  • Do not omit the resource identity when clients need to know where the new resource lives

Examples

New resource creation

Request:POST /api/posts
Response:201 Created with Location: /api/posts/456

The server confirms creation and tells the client where the new resource can be found.

References

Related 2xx Success Codes