UNPKG

ts5deco-express-controller

Version:

TypeScript 5 Modern Decorator Express Controller Framework

60 lines 2.22 kB
import { Response } from 'express'; import { BaseResponse } from './BaseResponse'; /** * Text response class for sending plain text with appropriate status codes * * @template TText - The type of the text data (defaults to string) * @template TStatus - The HTTP status code (defaults to number) * * @example * ```typescript * // Success text response with type safety * return new TextResponse<string, 200>(200, 'Operation completed successfully'); * * // Health check with literal type * return new TextResponse<'OK', 200>(200, 'OK'); * * // Error text with specific status * return new TextResponse<string, 400>(400, 'Bad Request'); * * // Using without generics (still works) * return new TextResponse(200, 'Hello World'); * ``` */ export declare class TextResponse<TText extends string = string, TStatus extends number = number> extends BaseResponse { readonly text?: TText | undefined; constructor(statusCode: TStatus, text?: TText | undefined); send(res: Response): void; /** * Static convenience methods for common text responses */ /** * 200 OK with text */ static ok<TText extends string = string>(text?: TText): TextResponse<TText | 'OK', 200>; /** * 201 Created with text */ static created<TText extends string = string>(text?: TText): TextResponse<TText | 'Created', 201>; /** * 400 Bad Request with text */ static badRequest<TText extends string = string>(text?: TText): TextResponse<TText | 'Bad Request', 400>; /** * 401 Unauthorized with text */ static unauthorized<TText extends string = string>(text?: TText): TextResponse<TText | 'Unauthorized', 401>; /** * 403 Forbidden with text */ static forbidden<TText extends string = string>(text?: TText): TextResponse<TText | 'Forbidden', 403>; /** * 404 Not Found with text */ static notFound<TText extends string = string>(text?: TText): TextResponse<TText | 'Not Found', 404>; /** * 500 Internal Server Error with text */ static internalError<TText extends string = string>(text?: TText): TextResponse<TText | 'Internal Server Error', 500>; } //# sourceMappingURL=TextResponse.d.ts.map