Mock 201 Created Response
Generate a 201 Created JSON response for POST endpoints. Includes the newly created resource with server-generated fields like id and timestamps.
Detailed Explanation
201 Created Response
A 201 status code indicates that a new resource was successfully created. The response body contains the complete created resource, including server-generated fields that were not in the original request.
Response Structure
{
"id": "a1b2c3d4-e5f6-4a5b-8c9d-0e1f2a3b4c5d",
"name": "New Resource",
"email": "user@example.com",
"role": "user",
"isActive": true,
"createdAt": "2026-02-27T14:30:00.000Z",
"updatedAt": "2026-02-27T14:30:00.000Z"
}
Server-Generated Fields
These fields appear in the response but were not in the request:
- id — Generated by the server (UUID or auto-increment)
- createdAt / updatedAt — Set to the current server time
- isActive — Default value applied by the server
- role — Default value if not specified in the request
Location Header
The HTTP response should also include a Location header pointing to the newly created resource:
HTTP/1.1 201 Created
Location: /api/users/a1b2c3d4-e5f6-4a5b-8c9d-0e1f2a3b4c5d
Content-Type: application/json
201 vs 200
Use 201 Created for POST endpoints that create new resources. Use 200 OK for operations that do not create a new resource (GET, PUT, PATCH, DELETE). This distinction helps clients and monitoring tools understand what happened.
Frontend Handling
After a successful creation:
- Redirect to the new resource's detail page
- Or add the returned object to the local list/cache
- Show a success notification
- Clear the creation form
Use Case
Frontend developers can use this mock to test POST form submission flows, including redirect-after-create patterns, cache updates, and success notifications.