Class: WebResponse
@divine/web-service.WebResponse
An HTTP response that is to be transmitted back to the client.
Hierarchy
WebResponse
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
| Name | Type | Description |
|---|---|---|
status | WebStatus | The HTTP status code to return. |
body? | null | string | number | bigint | boolean | object | Date | Buffer | ReadableStream | The HTTP response entity to return. |
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
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
| Name | Type | Description |
|---|---|---|
webreq | WebRequest | The request this is a response to. |
config | Required<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
| Name | Type | Description |
|---|---|---|
name | string | The name of the header to return (case-insensitive). |
value | undefined | string | number | boolean | string[] | The header value. |
Returns
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