stego/body

Types

Represents a request body received from a client. This value is consumed when read, meaning it can only be read once. https://developer.mozilla.org/en-US/docs/Web/API/Request#instance_methods

pub type Body

Functions

pub fn bit_array(body: Body) -> Promise(BitArray)

Parse the request body as binary, and receive it as a BitArray

Examples
import gleam/javascript/promise
import stego/body

use bytes <- promise.await(
  request.body
  |> body.bit_array()
)
pub fn json(body: Body) -> Promise(Dynamic)

Parse the request body as JSON, and receive it as a Dynamic

Examples
import gleam/dynamic
import gleam/javascript/promise
import gleam/json
import stego/body

use puppy_json <- promise.await(
  request.body
  |> body.json()
)

dynamic.decode3(
  Puppy,
  dynamic.field("name", of: dynamic.string),
  dynamic.field("good", of: dynamic.bool),
  dynamic.field("soft", of: dynamic.bool),
)
|> json.decode(from: puppy_json)
pub fn text(body: Body) -> Promise(String)

Parse the request body as text, and receive it as a String

Examples
import gleam/javascript/promise
import stego/body

use text <- promise.await(
  request.body
  |> body.text()
)
Search Document