UNPKG

restifyx.js

Version:

Advanced API endpoint handler system with automatic documentation

66 lines (65 loc) 2.12 kB
import type { Response } from "express"; declare global { var CURRENT_RESPONSE: Response | undefined; var CURRENT_REQUEST: any | undefined; } export declare class SendData { private static getResponse; /** * Send a JSON response * * @param data - The data to send * @param statusCode - HTTP status code (default: 200) * @param headers - Additional headers to include */ static json(data: any, statusCode?: number, headers?: Record<string, string>): void; /** * Send a text response * * @param text - The text to send * @param statusCode - HTTP status code (default: 200) * @param headers - Additional headers to include */ static text(text: string, statusCode?: number, headers?: Record<string, string>): void; /** * Send an HTML response * * @param html - The HTML to send * @param statusCode - HTTP status code (default: 200) * @param headers - Additional headers to include */ static html(html: string, statusCode?: number, headers?: Record<string, string>): void; /** * Send a file as a response * * @param filePath - Path to the file * @param options - Options for res.sendFile() */ static file(filePath: string, options?: any): void; /** * Redirect to another URL * * @param url - The URL to redirect to * @param statusCode - HTTP status code (default: 302) */ static redirect(url: string, statusCode?: number): void; /** * Send a 204 No Content response */ static noContent(): void; /** * Stream data as a response * * @param stream - The stream to send * @param statusCode - HTTP status code (default: 200) * @param headers - Additional headers to include */ static stream(stream: NodeJS.ReadableStream, statusCode?: number, headers?: Record<string, string>): void; /** * Get the response object from the current execution context * * @returns The Express response object * @private */ private static getResponseFromContext; }