package trail

  1. Overview
  2. Docs

Module TrailSource

# 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

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

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

Sourcetype trail = Conn.t -> Conn.t

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

Sourcetype 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 ```

Sourcemodule type Intf = sig ... end
Sourceval use : (module Intf with type args = 'args) -> 'args -> trail
Sourcemodule Logger : sig ... end
Sourcemodule Static : sig ... end
Sourcemodule CORS : sig ... end
Sourcemodule Router : sig ... end
Sourceval 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.