The StatusFlow function is the heart of the library. It takes an HTTP status code and returns a rich, structured response object with bilingual support, metadata, and customization options.
StatusFlow uses a comprehensive JSON catalog (http-statuses.json) that contains information about all standard HTTP status codes. For each code, the catalog stores:
Status code and name (in English and Spanish)
Category (Informational, Success, Redirection, Client Error, Server Error)
Description and possible causes
Default response structure
Customization options
When you call StatusFlow, it looks up the status code in this catalog and builds a response object in your chosen language.
The library exports a StatusFlowCodes object containing named constants for all HTTP status codes. This provides type-safe, readable code instead of magic numbers.
import { StatusFlow, StatusFlowCodes } from 'status-flow';// Instead of using magic numbersconst response1 = StatusFlow({ code: 404 });// Use named constants for better readabilityconst response2 = StatusFlow({ code: StatusFlowCodes.NOT_FOUND });const response3 = StatusFlow({ code: StatusFlowCodes.INTERNAL_SERVER_ERROR });const response4 = StatusFlow({ code: StatusFlowCodes.CREATED });
StatusFlow’s power comes from its comprehensive http-statuses.json catalog. Each entry contains:
{ "404": { "code": 404, "name": { "en": "Not Found", "es": "No Encontrado" }, "category": { "en": "Client Error", "es": "Error del Cliente" }, "description": { "en": "Standard HTTP client error code 404.", "es": "Código HTTP estándar de error del cliente 404." }, "possibleCauses": { "en": ["General cause depending on context."], "es": ["Causa general dependiendo del contexto."] }, "defaultResponse": { "en": { "success": false, "message": "HTTP 404 - Not Found", "code": 404 }, "es": { "success": false, "message": "HTTP 404 - No Encontrado", "code": 404 } }, "userCustomizable": { "extra": {} } }}
The catalog includes all standard HTTP status codes from 100-599, covering informational, success, redirection, client error, and server error responses.