Dream (project and README WIP)
Dream is an easy-to-use, feature-complete Web framework without any boilerplate.
let hello who =
<html>
<body>
<h1>Hello, <%s who %>!</h1>
</body>
</html>
let () =
Dream.run
@@ Dream.logger
@@ Dream.router [
Dream.get "/" (fun _ -> Dream.respond (hello "world"));
]
@@ Dream.not_found
All of Dream is one flat module, in one package, dream. Included
are:
- Easy HTTPS and HTTP/2 support, so you can choose to run Dream without a proxy.
- WebSockets and GraphQL for your modern Web apps.
- HTML templates with embedded OCaml — use existing skills!
- Composable middleware and routes.
- Easy-to-use to functions for secure cookies and CSRF-safe forms.
- Sessions with pluggable storage back ends.
- Unified, internationalization-friendly error handling.
- Cryptography helpers, key rotation, and a chosen cipher.
- A neat logger, and attention to configuring the OCaml runtime nicely.
Every part of the API is arranged to be easy to use, understand, and remember.
Dream sticks to base OCaml types like string and list, introducing only a
few types of its own — and some of those are just abbreviations
for bare functions!
The neat interface is not a limitation. Everything is still configurable by a large number of optional arguments. Where necessary, Dream exposes the lower-level machinery that it is composed from. For example, the default body and WebSocket readers return strings, but you can also do zero-copy streaming.
You can even run Dream as a quite bare abstraction over its underlying set of HTTP libraries, where it acts only as minimal glue code between their slightly different interfaces and takes care of horridness like ALPN.
Documentation
-
Dream has several dozen Examples, each of which is a complete project in the public domain.
-
The first examples make up a Tutorial. Visit to see the full list and start wherever you like, or begin at
1-hello, the Dream version of Hello, world! -
See the API documentation.
Getting started
opam install dream
Acknowledgements
Dream is based on work by the authors and contributors of its many dependencies and their transitive dependencies. There are, however, several influences that cannot be discovered directly:
- Templates are inspired by ECaml from Alexander Markov, and Embedded OCaml Templates from Emile Trotignon.
- Dream's handlers and middlewares are directly inspired by Opium from Rudi Grinberg and contributors.
- The lower-level HTTP and WebSocket servers are vendored copies of Antonio Nuno Monteiro's forks and original works, with credit also due to their contributors, and Spiros Eliopoulos in particular, as the original author of two of the projects.
- The API docs are instantiated by Soupault from Daniil Baturin.
- The name was inspired by Morph from Ulrik Strid, which was itself partially inspired by Opium.
- Raphael Rafatpanah and El-Hassan Wanas provided important early feedback.
Roadmap
1.0.0~alpha1:
- Finish more of the examples, cross-link everything.
- Correct the cipher rotation envelope scheme.
- Quick start script.
Then:
- Optimizations: router, logger, microparsers (form data, etc.), fully zero-allocation streaming.
- WebSocket and stream backpressure.
- HTTP3/QUIC.