glitr/body
This module exports types and functions related to the body of Routes
Types
A wrapper for an encoder and a decoder to convert from request/response data to and from a Gleam type
pub type BodyConverter(body_type) {
BodyConverter(
encoder: fn(body_type) -> string_builder.StringBuilder,
decoder: fn(String) -> Result(body_type, error.GlitrError),
)
}
Constructors
-
BodyConverter( encoder: fn(body_type) -> string_builder.StringBuilder, decoder: fn(String) -> Result(body_type, error.GlitrError), )
The type of body that can be expected from a Route
pub type BodyType {
EmptyBody
StringBody
JsonBody
}
Constructors
-
EmptyBody
-
StringBody
-
JsonBody
Functions
pub fn decode(
body: RouteBody(a),
value: String,
) -> Result(a, GlitrError)
Decode a value using the RouteBody’s decoder from a String
pub fn encode(body: RouteBody(a), value: a) -> StringBuilder
Encode a value using the RouteBody’s encoder into a StringBuilder
pub fn json_body(
encoder: fn(a) -> Json,
decoder: fn(Dynamic) -> Result(a, List(DecodeError)),
) -> RouteBody(a)
Create a RouteBody that will be converted from/to json
pub fn string_body(converter: BodyConverter(a)) -> RouteBody(a)
Create a RouteBody that will be converted from/to a string