Skip to main content

Class: WebResponse

@divine/web-service.WebResponse

An HTTP response that is to be transmitted back to the client.

Hierarchy​

Constructors​

constructor​

• new WebResponse(status, body?, headers?)

Constructs a new response object.

The body is currently serialized in the constructor according to the content-type header, but that will change in the future when accept content negotiation is added, so do not depend on that.

Parameters​

NameTypeDescription
statusWebStatusThe HTTP status code to return.
body?null | string | number | bigint | boolean | object | Date | Buffer | ReadableStreamThe HTTP response entity to return.
headersWebResponseHeadersThe HTTP headers to return. If the length of the response body is known, content-length will be added automatically.

Defined in​

web-service/src/response.ts:35

Properties​

body​

• body: null | Buffer | ReadableStream

The response body.

Defined in​

web-service/src/response.ts:22


headers​

• headers: WebResponseHeaders = {}

The HTTP headers to return. If the length of the response body is known, content-length will be added automatically.

Defined in​

web-service/src/response.ts:35


status​

• status: WebStatus

The HTTP status code to return.

Defined in​

web-service/src/response.ts:35

Methods​

close​

▸ close(): Promise<void>

Closes the response by destroying the body, in case it is a readable stream.

Returns​

Promise<void>

Defined in​

web-service/src/response.ts:80


serialize​

▸ serialize(webreq, config): Promise<RawResponse>

Serializes the response.

For successful GET and HEAD responses, if an etag response header matches the if-none-match request header, NOT_MODIFIED will be returned instead.

If returnRequestID is configured, the request ID will also be automatically added to the response.

Parameters​

NameTypeDescription
webreqWebRequestThe request this is a response to.
configRequired<WebServiceConfig>The WebService configuration.

Returns​

Promise<RawResponse>

A serialized response.

Defined in​

web-service/src/response.ts:99


setHeader​

▸ setHeader(name, value): WebResponse

Adds a custom header to the list of headers to return.

Parameters​

NameTypeDescription
namestringThe name of the header to return (case-insensitive).
valueundefined | string | number | boolean | string[]The header value.

Returns​

WebResponse

This WebResponse.

Defined in​

web-service/src/response.ts:73


toString​

▸ toString(): string

Returns a short description about this response, including status and content type.

Returns​

string

Defined in​

web-service/src/response.ts:133