tinyroute/router

Types

pub type Router {
  Router(
    routes: dict.Dict(
      route.Route,
      handler.Handler(BitArray, bytes_builder.BytesBuilder),
    ),
    not_found_handler: handler.Handler(
      BitArray,
      bytes_builder.BytesBuilder,
    ),
    log: Bool,
  )
}

Constructors

  • Router(
      routes: dict.Dict(
        route.Route,
        handler.Handler(BitArray, bytes_builder.BytesBuilder),
      ),
      not_found_handler: handler.Handler(
        BitArray,
        bytes_builder.BytesBuilder,
      ),
      log: Bool,
    )

Functions

pub fn add(
  router: Router,
  method: Method,
  path: String,
  handler: fn(Request(BitArray)) -> Response(BytesBuilder),
) -> Router

Adds a new handler to the routes with the given method and path

pub fn get_handler(
  router: Router,
) -> fn(Request(BitArray)) -> Response(BytesBuilder)

Gets the main handler that executes the respective handler for each route

pub fn new() -> Router

Creates a new Router

pub fn set_log(router: Router, value: Bool) -> Router

Sets the log flag

pub fn set_not_found_handler(
  router: Router,
  not_found_handler: fn(Request(BitArray)) ->
    Response(BytesBuilder),
) -> Router

Sets the not_found error handler to a custom one

Search Document