tspace-spear
Version:
tspace-spear is a lightweight, high-performance API framework for Node.js that leverages the native HTTP server and supports uWebSockets.js (C++) for maximum speed and efficiency.
32 lines (31 loc) • 910 B
TypeScript
import { OutgoingHttpHeaders } from 'http';
/**
* Sets the HTTP response headers and status code before the controller method executes.
*
* This decorator calls `res.writeHead()` on the underlying Node.js response object,
* allowing you to define the response **status code** and **headers** in advance.
*
* @example
* ```ts
* class UserController {
*
* \@WriteHeader(200, { "Content-Type": "application/json" })
* async profile(ctx: T.Context) {
* return { id: 1, name: "John" };
* }
*
* }
* ```
*
* Example response:
*
* ```
* HTTP/1.1 200 OK
* Content-Type: application/json
* ```
*
* @param {number} statusCode - HTTP status code to send with the response.
* @param {OutgoingHttpHeaders} contentType - Response headers to set.
* @returns {MethodDecorator}
*/
export declare const WriteHeader: (statusCode: number, contentType: OutgoingHttpHeaders) => MethodDecorator;