201 Created
Fault: Neither
TL;DR
Successfully created a new resource as a result of the request.
The request has been fulfilled and a new resource has been created.
What This Error Means
The request has been fulfilled and a new resource has been created.
Successfully created a new resource as a result of the request.
Common Causes
- Successful POST request creating a resource
- Successful PUT creating a new resource
How to Fix It (For Visitors)
- No action needed - resource created successfully
How to Fix It (For Developers/Admins)
- Return 201 when creating new resources via POST/PUT
- Include Location header with new resource URI
Code Examples
Here's how to return a 201 status code in various programming languages:
Python (Flask)
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/endpoint')
def endpoint():
return jsonify({"message": "Created"}), 201
Node.js (Express)
const express = require('express');
const app = express();
app.get('/endpoint', (req, res) => {
res.status(201).json({ message: 'Created' });
});
PHP
<?php
http_response_code(201);
header('Content-Type: application/json');
echo json_encode(['message' => 'Created']);
?>
Go
package main
import (
"encoding/json"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(201)
json.NewEncoder(w).Encode(map[string]string{
"message": "Created",
})
}
Java (Spring Boot)
@GetMapping("/endpoint")
public ResponseEntity<Map<String, String>> endpoint() {
Map<String, String> response = new HashMap<>();
response.put("message", "Created");
return ResponseEntity.status(201).body(response);
}
Ruby (Sinatra)
get '/endpoint' do
status 201
json message: 'Created'
end
Browser Compatibility
| Browser | Support | Notes |
|---|---|---|
| Chrome | ✓ Full Support | All versions |
| Firefox | ✓ Full Support | All versions |
| Safari | ✓ Full Support | All versions |
| Edge | ✓ Full Support | All versions |
Official Specification
This status code is defined in RFC 7231 Section 6.3.2.