• Stars
    star
    1,596
  • Rank 29,317 (Top 0.6 %)
  • Language
    OCaml
  • License
    MIT License
  • Created over 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tidy, feature-complete Web framework

Dream

Easy-to-use, feature-complete Web framework without boilerplate.


Quick Start | Playground | Tutorial | Reference Β Β 



Dream is one flat module in one package, documented on one page, but with many examples. It offers:


...all without sacrificing ease of use β€” Dream has:

  • A simple programming model β€” Web apps are just functions!
  • Composable middleware and routes.
  • Unified, internationalization-friendly error handling.
  • Cryptography helpers, key rotation, and a chosen cipher.
  • A neat logger, and attention to configuring the OCaml runtime nicely.
  • Deployment instructions for Digital Ocean, Heroku, and Fly.io, with sample CI scripts.

Every part of the API is arranged to be easy to understand, use, 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, and very loose coupling. Where necessary, Dream exposes the lower-level machinery that it is composed from. For example, the basic 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, even though Dream is presented as one package for ordinary usage, it is internally factored into several sub-libraries, according to the different dependencies of each, for fast porting to different environments.

Dream is a low-level and unopinionated framework, and you can swap out its conveniences. For example, you can use TyXML with server-side JSX instead of Dream's built-in templates. You can bundle assets into a single Dream binary, or use Dream in a subcommand. Dream tries to be as functional as possible, touching global runtime state only lazily, when called into.


Quick start

Visit one of the first tutorials in the online playground, and read its docs. You can get and build it locally with:

bash -c "$(curl -fsSL https://raw.githubusercontent.com/aantron/dream/master/example/quickstart.sh)"

Most of the other examples are also loaded in the playground. See the links on its home page.

esy

Visit any of the examples, such as 2-middleware, and re-create the files locally. The file esy.json shows how to depend on Dream. All of the examples are installed by running npx esy, and started with npx esy start.

opam

opam install dream

After that, go to any of the examples, such as 2-middleware, re-create the files locally, and run it:

dune exec ./middleware.exe

Documentation


Recommended projects

  • dream-cli Β β€”Β  command-line interface for Dream applications.
  • dream-encoding Β β€” Β  compression middleware.
  • dream-livereload Β β€”Β  live reloading.
  • emile Β β€”Β  email address syntax validation.
  • letters Β β€”Β  SMTP client.

Example repositories


Contact

Apart from the issues, good places to discuss Dream are...

Highlight @antron to poke @aantron specifically.


Contributing

All kinds of contributions are welcome, including examples, links to blogs, related libraries, and, of course, PRs! See CONTRIBUTING.md.

As an immediate note, if you'd like to clone the repo, be sure to use --recursive, because Dream uses several git submodules:

git clone https://github.com/aantron/dream.git --recursive

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:

More Repositories

1

better-enums

C++ compile-time enum to string, iteration, in a single header file
C++
1,638
star
2

lambdasoup

Functional HTML scraping and rewriting with CSS in OCaml
OCaml
379
star
3

promise

Light and type-safe binding to JS promises
Reason
341
star
4

bisect_ppx

Code coverage for OCaml and ReScript
OCaml
303
star
5

luv

Cross-platform asynchronous I/O and system calls
OCaml
275
star
6

markup.ml

Error-recovering streaming HTML5 and XML parsers
OCaml
146
star
7

namespaces

Sane file naming for OCaml projects.
OCaml
71
star
8

hyper

OCaml Web client, composable with Dream [unannounced]
OCaml
68
star
9

dream-serve

Live-reloading server for static sites (eventually also dynamic)
OCaml
50
star
10

repromise_lwt

OCaml
13
star
11

faster-map

A tail-recursive list map with good performance for all list sizes. Not actually written in assembly.
Assembly
13
star
12

reason-native-hello

The smallest possible Reason Native project
Reason
11
star
13

bisect-starter-dune

Bisect_ppx + Dune starter repo
OCaml
6
star
14

bisect-starter-rescript

Bisect_ppx + ReScript starter repo
ReScript
5
star
15

binaries

OCaml binaries for all the platforms
Shell
5
star
16

promise-example-binding

reason-promise binding to node-fetch
Reason
4
star
17

bisect-starter-esy

Bisect_ppx + esy starter repo
OCaml
3
star
18

promise-example-bsb

Hello world using reason-promise
Reason
3
star
19

promise-example-esy

Using native reason-promise with esy
OCaml
3
star
20

bisect-ci-integration-megatest

Bisect_ppx web integrations testing
OCaml
2
star
21

bisect-starter-jsoo

Bisect_ppx + Js_of_ocaml starter repo
OCaml
1
star
22

ocamlformat-binary

Just storage for an Ocamlformat to use in Bisect_ppx's CIs
1
star
23

lwt-manual

OCaml
1
star
24

bisect-starter-jest

Bisect_ppx + Jest starter repo
ReScript
1
star
25

dream-branches

Archived branches from the main Dream repo
OCaml
1
star