Skip to content

JsonHttpResponse

Creates a JSON response by serializing data with JSON.stringify() and setting Content-Type to application/json; charset=utf-8.

Importing

ts
import { JsonHttpResponse } from '@almighty-shogun/bun-server';

Usage

ts
import { HttpStatus, JsonHttpResponse } from '@almighty-shogun/bun-server';

const response = new JsonHttpResponse({ ok: true }, HttpStatus.Ok);

Parameters

data: T
Value serialized with JSON.stringify().

status: HttpStatus
HTTP status code for the response.

headers?: HeadersInit
Response headers.

Returns

A JSON Response subclass.

Type signature

ts
declare class JsonHttpResponse<T = unknown> extends HttpBaseResponse {
    constructor(data: T, status: HttpStatus, headers?: HeadersInit);
}

All packages are released under the MIT License.