Skip to content

Request Body Classes

Dickson Law edited this page Apr 9, 2023 · 1 revision

Request Body Classes

These classes are meant to be used with the body parameter in request-sending functions.

StructBody(data)

An application/json request body encoded using json_stringify.

Fields

  • data: The data struct associated with this request body.

Methods

  • addValue(k, v): Add a new key-value pair to this request body.
  • getBody(): Return the request body as a string.

Example

new StructBody({
    name: "Alice Anderson",
    email: "alice.anderson@example.com",
})

XwfuBody(data)

An application/x-www-form-urlencoded request body.

Fields

  • data: The data struct associated with this request body.

Methods

  • addValue(k, v): Add a new key-value pair to this request body.
  • getBody(): Return the request body as a string.

Example

new XwfuBody({
    name: "Alice Anderson",
    email: "alice.anderson@example.com",
})

MultipartBody(data)

A multipart/form-data request body. Only with this body type can you attach files as multipart file parts in a key-value pair.

Fields

  • data: The data struct associated with this request body.

Methods

  • addValue(k, v): Add a new key-value pair to this request body.
  • getBody(): Return the request body as a buffer.
  • cleanBody(): Free the memory associated with the generated body buffer.

Example

new MultipartBody({
    name: "Alice Anderson",
    email: "alice.anderson@example.com",
    avatar: new FilePart("avatar.png"),
})

JsonBody(data)

An application/json request body encoded using the JSON Structs library.

IMPORTANT: Please use StructBody instead if you are not using the JSON Structs library.

Fields

  • data: The data struct associated with this request body.

Methods

  • addValue(k, v): Add a new key-value pair to this request body.
  • getBody(): Return the request body as a string.

Example

new JsonBody({
    name: "Alice Anderson",
    email: "alice.anderson@example.com",
})

Clone this wiki locally