mirror of
https://github.com/aantron/dream.git
synced 2025-12-09 00:03:47 -05:00
Tutorial
Dream's first several examples make up a tutorial. Each example is a
complete project with a helpful README, and plenty of links to next steps and
documentation. You can begin at 1-hello, or look in the
list below and jump to whatever interests you!
1-hello— the simplest Dream server responds to every request with the same friendly message.2-middleware— adds the first Dream middleware: the logger.3-router— different handlers for different paths.4-counter— the first custom middleware!5-promise— introduces Lwt, the promise library used by Dream.6-echo— reads request bodies.7-template— renders responses from inline HTML templates and guards against XSS.8-debug— includes detailed information about errors in responses.9-error— customize all error responses in one place.a-log— writing messages to Dream's log.b-session— associates state with client sessions.c-cookie— sets custom cookies.d-form— reads forms with CSRF prevention.e-json— sends and receives JSON securely.f-static— serves static files from a local directory.g-upload— receives file uploads.h-sql— queries an SQL database.i-graphql— serves a GraphQL schema and GraphiQL.j-stream— streams request and response bodies.k-websocket— opens a WebSocket between client and server.l-https— enables HTTPS and HTTP/2 upgrades.
That's it for the tutorial!
Reason
There are several examples showing Dream with Reason syntax.
r-hello— the simplest Dream server.r-template— renders HTML templates and protects against XSS.r-template-stream— streams templates as response bodies.
Full-stack
r-fullstack-melange— server and client written in Reason!w-fullstack-rescript— shares OCaml code between server and client using ReScript.w-fullstack-jsoo— shares OCaml code between server and client using js_of_ocaml.
Examples
The rest of the examples cover additional topics in a more standalone fashion. The goal of the examples is to (eventually) cover the great majority of real-world HTTP usage, so that they make up a good survey. Please open an issue if something is missing!
w-graphql-subscription— GraphQL subscriptions.w-esy— gives detail on packaging with esy, an npm-like package manager.w-one-binary— bakes static assets into a self-contained server binary.w-fswatch— sets up a development watcher using fswatch.w-tyxml— uses TyXML for type-checked HTML templating.w-long-polling— old form of asynchronous communication without WebSockets.w-query— reads URL query parameters.w-server-sent-events—EventSource, an older alternative to WebSockets.w-template-stream— sends templates asynchronously, one chunk at a time.w-stress-response— benchmarks streaming very large responses.w-stress-websocket-send— benchmarks sending WebSocket messages quickly.w-multipart-dump— echoesmultipart/form-databodies for debugging.z-playground— source code of the Dream playground.
Roadmap
These examples will be trickled in during the alpha releases.
Ideas:
w-auto-reloadw-fullstack-rescript— done.w-index-htmlw-one-binaryw-ppx-derivingw-react-spaw-subcommandw-template-directoryw-tyxml— for TyXML templates.w-chatw-fullstack-brr
Basics:
w-content-negotiationw-query— done.w-scope— forDream.scope.w-subsite— for*routes.w-testing— for Testing.w-site-prefix— a Web app running not at/.
Security:
w-authw-cookie-session— forDream.cookie_sessions.w-corsw-sql-session— forDream.sql_sessions.w-file-sessionw-form-expired— for other cases ofDream.form.w-json-csrf— forDream.csrf_tokenandX-CSRF-Token:.w-jwtw-key-rotation— for a to-be-added~secretsargument toDream.run, which can specify multiple decryption keys.w-upload-csrf— forDream.csrf_tokenwithDream.upload.
Techniques:
w-etagw-graphql-sqlw-graphql-mutationw-graphql-subscriptionsw-https-redirectw-long-polling— done.w-postgres-dockerw-server-sent-events— done.w-sql-streamw-template-stream— done.w-websocket-streamr-graphql