Class: ApiRequest
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:11
Extends
IncomingMessage
Constructors
new ApiRequest()
new ApiRequest(
socket
:Socket
):ApiRequest
Defined in: node_modules/@types/node/http.d.ts:1173
Parameters
Parameter | Type |
---|---|
socket | Socket |
Returns
Inherited from
IncomingMessage.constructor
Properties
#cachedRequest
private
#cachedRequest:null
|Request
=null
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:63
The response object. This field is cached to prevent multiple response objects from being created.
auth?
optional
auth:null
|AuthData
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:29
The authorization information. This field indicates three possible values:
undefined
: The authorization middleware has not been executed yet.null
: The user is not authorized.AuthData
: The user is authorized.
params
params:
Record
<string
,string
> ={}
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:20
The URI parameters.
query
query:
Record
<string
,string
|string
[]> ={}
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:15
The query parameters.
route?
optional
route:null
|Route
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:57
The route that matched the request. The field indicates three possible values:
undefined
: The router handler has not been executed yet.null
: The router handler has been executed, but no route matched the request.Route
: The router handler has been executed and a route matched the request.
Since
7.0.0
routerNode?
optional
routerNode:null
|RouterNode
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:43
The router node that matched the request. The field indicates three possible values:
undefined
: The router handler has not been executed yet.null
: The router handler has been executed, but no node matched the request.RouterNode
: The router handler has been executed and a node matched the request.
Since
7.0.0
Accessors
#isFormContentType
Get Signature
get
private
#isFormContentType():boolean
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:65
Returns
boolean
Methods
asWeb()
asWeb():
Request
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:78
The response object, used to validate the request's headers and body.
Returns
Request
readBody()
readBody():
Promise
<unknown
>
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:93
Reads the request body and tries to parse using JSON or form-urlencoded.
Returns
Promise
<unknown
>
The result of the body parsing
Example
const body = await request.readBody();
readBodyArrayBuffer()
readBodyArrayBuffer():
Promise
<ArrayBuffer
>
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:102
Reads the request body as an ArrayBuffer.
Returns
The result of the body parsing
readBodyBlob()
readBodyBlob():
Promise
<Blob
>
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:111
Reads the request body as a Blob.
Returns
Promise
<Blob
>
The result of the body parsing
readBodyFormData()
readBodyFormData():
Promise
<FormData
>
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:127
Reads the request body as a FormData.
Returns
Promise
<FormData
>
The result of the body parsing
Remarks
This will throw an error if the content type is not one of the following:
application/x-www-form-urlencoded
multipart/form-data
readBodyJson()
readBodyJson():
Promise
<unknown
>
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:137
Reads the request body as text, using TextDecoder. Afterward, it parses the body as JSON with JSON.parse.
Returns
Promise
<unknown
>
The result of the body parsing
readBodyText()
readBodyText():
Promise
<string
>
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:146
Reads the request body as text, using TextDecoder.
Returns
Promise
<string
>
The result of the body parsing
readValidatedBody()
readValidatedBody<
Type
>(validator
:ValidatorFunction
<unknown
,Type
>):Promise
<Type
>
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:156
Identical to ApiRequest.readBody, but it validates the result.
Type Parameters
Type Parameter |
---|
Type |
Parameters
Parameter | Type | Description |
---|---|---|
validator | ValidatorFunction <unknown , Type > | The validator function to use on the body parsing result |
Returns
Promise
<Type
>
The validated body
readValidatedBodyFormData()
readValidatedBodyFormData<
Type
>(validator
:ValidatorFunction
<FormData
,Type
>):Promise
<Type
>
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:167
Identical to ApiRequest.readBodyFormData, but it validates the result.
Type Parameters
Type Parameter |
---|
Type |
Parameters
Parameter | Type | Description |
---|---|---|
validator | ValidatorFunction <FormData , Type > | The validator function to use on the body parsing result |
Returns
Promise
<Type
>
The validated body
readValidatedBodyJson()
readValidatedBodyJson<
Type
>(validator
:ValidatorFunction
<unknown
,Type
>):Promise
<Type
>
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:177
Identical to ApiRequest.readBodyJson, but it validates the result.
Type Parameters
Type Parameter |
---|
Type |
Parameters
Parameter | Type | Description |
---|---|---|
validator | ValidatorFunction <unknown , Type > | The validator function to use on the body parsing result |
Returns
Promise
<Type
>
The validated body
readValidatedBodyText()
readValidatedBodyText<
Type
>(validator
:ValidatorFunction
<string
,Type
>):Promise
<Type
>
Defined in: projects/plugins/packages/api/src/lib/structures/api/ApiRequest.ts:187
Identical to ApiRequest.readBodyText, but it validates the result.
Type Parameters
Type Parameter |
---|
Type |
Parameters
Parameter | Type | Description |
---|---|---|
validator | ValidatorFunction <string , Type > | The validator function to use on the body parsing result |
Returns
Promise
<Type
>
The validated body