Skip to main content
Version: 1.2.0

Class: PetitioResponse#

PetitioResponse.PetitioResponse

Constructors#

constructor#

+ new PetitioResponse(): PetitioResponse

Returns: PetitioResponse

Properties#

body#

• body: Buffer

The response body received from the server. This is updated in chunks through PetitioResponse._addChunk, either from PetitioRequest.send or directly on a response object from another source.

Defined in: lib/PetitioResponse.ts:12


headers#

• headers: object

The response headers received from the server. This is updated through PetitioResponse._parseHeaders.

Type declaration:#

Defined in: lib/PetitioResponse.ts:17


statusCode#

• statusCode: null | number= null

The status code received from the server. This is set only after the response is complete when headers are received or it can be set manually.

Defined in: lib/PetitioResponse.ts:23

Methods#

_addChunk#

â–¸ _addChunk(chunk: Buffer | Uint8Array): void

This appends data to the body, dynamically reallocating the buffer size as chunks are added. Therefore, this is currently unsuitable for handling large responses, as the exact size is allocated in memory as a buffer.

Parameters:#

NameTypeDescription
chunkBuffer | Uint8ArrayThe chunk of data to append to the body.

Returns: void

In place operation with no return.

Defined in: lib/PetitioResponse.ts:32


_parseHeaders#

â–¸ _parseHeaders(headers: string[]): void

Parameters:#

NameTypeDescription
headersstring[]The headers to add. This is done by splitting the array into chunks of two, where the first value becomes the header and the latter becomes its value. This will also append values to the header as an array if it already exists.

Returns: void

In place operation with no return.

Defined in: lib/PetitioResponse.ts:43


json#

â–¸ json<T>(encoding?: BufferEncoding): T

Type parameters:#

NameDefaultDescription
TanyType casting parameter for the JSON result.

Parameters:#

NameTypeDefault value
encodingBufferEncoding"utf8"

Returns: T

A serialized object result parsed from the response body.

Defined in: lib/PetitioResponse.ts:62


text#

â–¸ text(encoding?: BufferEncoding): string

Parameters:#

NameTypeDefault value
encodingBufferEncoding"utf8"

Returns: string

The response body decoded as as a string from the buffer, using either the encoding specified in encoding or UTF-8 by default..

Defined in: lib/PetitioResponse.ts:70

Last updated on