package trail

  1. Overview
  2. Docs

# Trail

Trail is a minimalistic, composable framework for building HTTP/S and WebSocket servers, inspired by Plugplug and WebSockwebsock. It provides its users with a small set of abstractions for building _trails_ that can be assembled to handle a request.

To create a Trail, you can use the syntax `Trail.fn1;fn2;fn3;...`, where each function takes a connection object and produces a new connection object.

For example:

```ocaml Trail. logger {level=Debug}; request_id {kind=Uuid_v4}; cqrs_token (); session {salt="3FBYQ5+B"}; (fun conn req -> conn |> send_resp ~status:`OK ~body:"hello world!"); ```

Trail also comes with support for Riotriot, and to start a Trail supervision tree you can call `Trail.start_link ~port trail`.

riot: https://github.com/leostera/riot plug: https://hexdocs.pm/plug/readme.html websock: https://hexdocs.pm/websock/readme.html

module Frame : sig ... end
module Sock : sig ... end
module Response : sig ... end
module Request : sig ... end
module Adapter : sig ... end
module Conn : sig ... end

The `Conn` module includes functions for handling an ongoing connection.

type trail = Conn.t -> Conn.t

A trail is a function that given a connection and some options, will produce a new connection object.

type t = trail list

The `Trail.t` is the type of the trail _pipelines_.

You can create new pipelines by using the syntax:

```ocaml Trail. logger ~level:Info (); request_id { kind:Uuid_v4 }; my_authentication; my_authorization; my_handler ```

module type Intf = sig ... end
val use : (module Intf with type args = 'args) -> 'args -> trail
module Logger : sig ... end
module Static : sig ... end
module CORS : sig ... end
module Router : sig ... end
val handler : Adapter.t -> (Conn.t -> Conn.t) list -> Atacama.Connection.t -> Request.t -> [> `close | `upgrade of [ `h2c | `websocket of Sock.upgrade_opts * Sock.t ] ]
OCaml

Innovation. Community. Security.