HTTP Status Codes
Centralized, type-safe HTTP status codes for consistent Next.js API responses.
Installation Guide
npx servercn-cli@latest add http-status-codes Usage Example
import { STATUS_CODES } from "@/constants/status-codes";import { NextResponse } from "next/server";
export async function GET() {
return NextResponse.json(
{ message: "OK" },
{ status: STATUS_CODES.OK }
);
}import { NextResponse } from "next/server";
export async function POST() {
return NextResponse.json(
{ error: "Unauthorized" },
{ status: STATUS_CODES.UNAUTHORIZED }
);
}Status Code Reference
| Status Code | Constant | Description |
| |
| 200 | OK | Request succeeded. |
| 201 | CREATED | Resource created successfully. |
| 202 | ACCEPTED | Request accepted for processing. |
| 204 | NO_CONTENT | Request succeeded with no response body. |
| 301 | MOVED_PERMANENTLY | Resource moved permanently. |
| 302 | FOUND | Resource found at a temporary location. |
| 304 | NOT_MODIFIED | Resource not modified since last request. |
| 400 | BAD_REQUEST | Invalid request from the client. |
| 401 | UNAUTHORIZED | Authentication required. |
| 403 | FORBIDDEN | Client does not have access. |
| 404 | NOT_FOUND | Resource not found. |
| 409 | CONFLICT | Conflict with current state of resource. |
| 422 | UNPROCESSABLE_ENTITY | Valid request but semantic errors present. |
| 429 | TOO_MANY_REQUESTS | Client sent too many requests. |
| 500 | INTERNAL_SERVER_ERROR | Server encountered an error. |
| 501 | NOT_IMPLEMENTED | Server does not support functionality. |
| 502 | BAD_GATEWAY | Invalid response from upstream server. |
| 503 | SERVICE_UNAVAILABLE | Server unavailable or overloaded. |
| 504 | GATEWAY_TIMEOUT | Upstream server timed out. |