cowboy/cowboy

This is a simple wrapper over the erlang cowboy server. It is originall from gleam-lang/cowboy but has been modified to work with espresso.

original source: https://github.com/gleam-lang/cowboy/blob/83e2f20170e4a73e5499238149313f8329a2f41a/src/gleam/http/cowboy.gleam

Types

An incoming request that will be handled by the dispatch in gleam_cowboy_native.erl

pub external type CowboyRequest

The returned result of cowboy_router:compile

pub external type CowboyRouter

A Route can either be a service (a function that handles a request and response) or a router which is expanded into a list of services.

pub type Route {
  ServiceRoute(Service(BitString, BitBuilder))
  RouterRoute(Routes)
}

Constructors

  • ServiceRoute(Service(BitString, BitBuilder))
  • RouterRoute(Routes)

Routes are the mapping between a path and the route. For example /hello -> hello_service

pub type Routes =
  Map(String, Route)

Functions

pub fn router(routes: Map(String, Route)) -> CowboyRouter

Takes a list of route structures and compiles them into a cowboy router.

pub fn start(router: CowboyRouter, on_port number: Int) -> Result(
  Pid,
  Dynamic,
)

Start the cowboy server on the given port.

Search Document