ResponseInfo class

const responseInfo = new ResponseInfo(data: ServerResponse);

constructor

The constructor of the ResponseInfo class requires one argument. The argument must be an instance of the NodeJS built-in HTTP ServerResponse class which provides the data for the ResponseInfo class.

Functions

setStatusCode

responseInfo.setStatusCode(statusCode: number) : void;

Sets the status code for the response which the client will receive.

ArgumentDescription

statusCode

A number which defines the status code the client will receive once the request has been handled and a response will be made.

setHeaders

responseInfo.setHeaders(headers: object) : void;

Sets custom response headers which the client will receive.

ArgumentDescription

headers

An object with the headers the client should receive. The key of the object must be the header name and the value of the object must be the value of the corresponding header name.

send

responseInfo.send(response: string | Buffer | undefined) : void;

Sends the response to the client.

ArgumentDescription

response

A string, instance of the Buffer class or undefined which defines the response the client should receive from the server.

end

responseInfo.end(response: string | Buffer | undefined) : void;

Identicial to the send function and sends a response to the client.

ArgumentDescription

response

A string, instance of the Buffer class or undefined which defines the response the client should receive from the server.

write

responseInfo.write(chunk: string | Buffer | undefined) : void;

Writes a response for the client, but doesn't send it yet. The response will be send once the send or end function gets called.

ArgumentDescription

chunk

A string, instance of the Buffer class or undefined which defines a part of the response the client should receive from the server.

setStatus

responseInfo.setStatus(statusCode?: number, headers?: object) : void;

Sets the status for the page the client made a request to.

Argument

statusCode

A number which defines the status code the client will receive once the request has been handled and a response will be made.

headers

An object with the headers the client should receive. The key of the object must be the header name and the value of the object must be the value of the corresponding header name.

Last updated