Logo
DevUtilsAll-in-one toolkit
Back to all codes
2012xx
2xx — Success

Created

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

What it means

The HTTP 201 Created success status response code indicates that the request has succeeded and has led to the creation of a resource.

The new resource, or a description and link to the new resource, is effectively created before the response is sent back and the newly created items are returned in the body of the message, whose location is represented by a `Location` header.

How it works

  • 1The client sends a POST or PUT request containing data to create a new entity.
  • 2The server validates the data, generates a new ID, and saves the entity to the database.
  • 3The server responds with '201 Created', typically including a 'Location' header pointing to the new resource's URI.
  • 4The response body often contains the newly created JSON object.

Why you're seeing this

  • A resource was successfully created.

How to fix it

  • Ensure you are reading the `Location` header or the response body to get the ID or URI of the newly created resource.

Framework Implementations

Django Rest Framework

from rest_framework import status
from rest_framework.response import Response

def create_item(request):
    # ... logic ...
    return Response(data, status=status.HTTP_201_CREATED)

Real-Life Scenarios

Use this whenever a client successfully creates a new database record, file, or entity via a POST or PUT request.

Registering a New User

A user fills out a signup form and submits a POST request to /users. The server creates the user in the database and returns 201 Created.

Uploading a File

A client uploads an image to a media server. The server responds with 201 Created and provides the URL to the new image.

HTTP Transaction

1. Client Request

POST /api/v1/orders HTTP/1.1
Host: api.store.com
Content-Type: application/json

{
  "productId": 99,
  "quantity": 2
}

2. Server Response

HTTP/1.1 201 Created
Location: /api/v1/orders/8014
Content-Type: application/json

{
  "orderId": 8014,
  "status": "processing"
}

SEO Implications

Generally no direct SEO impact as 201 Created is typically the result of a POST request (which search engines do not perform).

Related Codes