gleatter/path
This module exports types and functions related to the path of Routes
Types
A wrapper for an encoder and a decoder to convert from request/response path to and from a Gleam type
The decoder should return Error(Nil) if the input path doesn’t correspond to the expected pattern
pub type PathConverter(path_type) {
PathConverter(
encoder: fn(path_type) -> List(String),
decoder: fn(List(String)) -> Result(path_type, Nil),
)
}
Constructors
-
PathConverter( encoder: fn(path_type) -> List(String), decoder: fn(List(String)) -> Result(path_type, Nil), )
The type of path that can be expected from a Route
pub type PathType {
StaticPath(root: List(String))
ComplexPath
}
Constructors
-
StaticPath(root: List(String))
-
ComplexPath
Functions
pub fn complex_path(converter: PathConverter(a)) -> RoutePath(a)
Create a more complex RoutePath from a custom converter
pub fn decode(
path: RoutePath(a),
value: List(String),
) -> Result(a, Nil)
Decode a value using the RoutePath’s decoder from path segments
pub fn encode(path: RoutePath(a), value: a) -> List(String)
Encode a value using the RoutePath’s encoder into path segments
pub fn id_path(root: List(String)) -> RoutePath(String)
Create a RoutePath that will match path of the type /x/y/z/:id
The id has to be the last segment of the path
pub fn static_path(root: List(String)) -> RoutePath(Nil)
Create a RoutePath that will solely match a static path