https://github.com/suri-framework/trail
Minimal composable server framework for Riot
https://github.com/suri-framework/trail
Last synced: 3 months ago
JSON representation
Minimal composable server framework for Riot
- Host: GitHub
- URL: https://github.com/suri-framework/trail
- Owner: suri-framework
- License: mit
- Created: 2023-11-15T06:02:01.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-30T09:54:57.000Z (almost 2 years ago)
- Last Synced: 2024-05-02T06:18:58.732Z (almost 2 years ago)
- Language: OCaml
- Homepage:
- Size: 85 KB
- Stars: 40
- Watchers: 3
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome - suri-framework/trail - Minimal composable server framework for Riot (<a name="OCaml"></a>OCaml)
README
# Trail
Trail is a minimalistic, composable framework for building HTTP/WebSocket
servers, inspired by [Plug][plug] & [WebSock][websock]. 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 an arbitrary context, to produce a new
connection object.
For example:
```ocaml
open Trail
open Router
let endpoint =
[
use (module Logger) Logger.(args ~level:Debug ());
router
[
socket "/ws" (module My_handler) ();
get "/" (fun conn -> Conn.send_response `OK {%b|"hello world"|} conn);
scope "/api"
[
get "/version" (fun conn ->
Conn.send_response `OK {%b|"none"|} conn);
];
];
]
```
[riot]: https://github.com/leostera/riot
[plug]: https://hexdocs.pm/plug/readme.html