Skip to main content
The StatusFlow function is the core utility of the library that generates standardized HTTP response objects with bilingual support (English and Spanish).

Function Signature

function StatusFlow(options: StatusFlowOptions): object

Parameters

The function accepts a single options object with the following properties:
code
number
required
The HTTP status code. Must be a valid HTTP status code (e.g., 200, 404, 500).If an invalid or unsupported code is provided, the function returns a generic error response.
lang
'en' | 'es'
default:"'es'"
The language for the response message.
  • 'en': English
  • 'es': Spanish (default)
This determines which language is used for the message, category, description, and possible causes in the response.
extra
Record<string, any>
default:"{}"
Additional custom fields to include in the response object.These fields are spread into the final response, allowing you to add application-specific data to the standardized response structure.
overrideMessage
string
Custom message to replace the default message for the status code.When provided, this overrides the standard message from the status code database while preserving all other metadata.

StatusFlowOptions Interface

interface StatusFlowOptions {
  code: number;
  lang?: StatusFlowLang;
  extra?: Record<string, any>;
  overrideMessage?: string;
}

type StatusFlowLang = 'es' | 'en';

Return Value

The function returns an object with the following structure:
success
boolean
Indicates whether the status code represents a successful response.
  • true for 1xx, 2xx, and 3xx status codes
  • false for 4xx and 5xx status codes
message
string
The message associated with the status code in the specified language.If overrideMessage was provided in the options, this will be the custom message.
code
number
The HTTP status code that was requested.
info
object
Additional metadata about the status code.
...extra
any
Any additional fields provided in the extra parameter are spread into the response.

Examples

Basic Usage

import { StatusFlow } from 'status-flow';

const response = StatusFlow({ code: 200 });
console.log(response);
Output:
{
  "success": true,
  "message": "HTTP 200 - Correcto",
  "code": 200,
  "info": {
    "name": "Correcto",
    "category": "Éxito",
    "description": "Código HTTP estándar de éxito 200.",
    "possibleCauses": ["Causa general dependiendo del contexto."]
  }
}

Using English Language

const response = StatusFlow({ 
  code: 404, 
  lang: 'en' 
});
console.log(response);
Output:
{
  "success": false,
  "message": "HTTP 404 - Not Found",
  "code": 404,
  "info": {
    "name": "Not Found",
    "category": "Client Error",
    "description": "Standard HTTP client error code 404.",
    "possibleCauses": ["General cause depending on context."]
  }
}

With Custom Message

const response = StatusFlow({ 
  code: 400,
  lang: 'en',
  overrideMessage: 'Invalid email format provided'
});
console.log(response);
Output:
{
  "success": false,
  "message": "Invalid email format provided",
  "code": 400,
  "info": {
    "name": "Bad Request",
    "category": "Client Error",
    "description": "Standard HTTP client error code 400.",
    "possibleCauses": ["General cause depending on context."]
  }
}

With Extra Fields

const response = StatusFlow({ 
  code: 201,
  lang: 'en',
  extra: {
    userId: '12345',
    timestamp: new Date().toISOString(),
    resource: '/api/users'
  }
});
console.log(response);
Output:
{
  "success": true,
  "message": "HTTP 201 - Created",
  "code": 201,
  "userId": "12345",
  "timestamp": "2026-03-07T12:00:00.000Z",
  "resource": "/api/users",
  "info": {
    "name": "Created",
    "category": "Success",
    "description": "Standard HTTP success code 201.",
    "possibleCauses": ["General cause depending on context."]
  }
}

Error Case - Invalid Code

const response = StatusFlow({ code: 999 });
console.log(response);
Output:
{
  "success": false,
  "message": "Código HTTP desconocido: 999",
  "code": 999
}

Use Cases

  • Consistent API Responses: Generate uniform response structures across your API
  • Bilingual Applications: Easily switch between English and Spanish responses
  • Error Handling: Provide detailed error information with context
  • Logging: Include structured metadata for debugging and monitoring
  • Client Communication: Send standardized, localized error messages to clients

Build docs developers (and LLMs) love