package dream-html

  1. Overview
  2. Docs
HTML generator eDSL for Dream

Install

Dune Dependency

Authors

Maintainers

Sources

dream-html-3.10.0.tbz
sha256=64c4eefc0ff2a7a8d6f7de5a0242e2d0a5044e50ce0bc292b7c356509cb28346
sha512=0528e6fe044626c5f663f4d0fddf79a2b497b69c90d7aa656e9b8c789b1a68a5464a7a0f8f6a81001d3429e6906a6f7e33cd2a9fb6f5f3f1564bfa45ae4e9d57

doc/ppx/Ppx/index.html

Module PpxSource

This PPX provides an extension point to create route paths.

You can add it to your dune file in the usual way: (preprocess (pps dream-html.ppx)).

Then create a path: let%path orders = "/orders".

And use it in a route: Dream_html.get orders (fun req -> ...).

The PPX expands the above path to:

  let orders = Dream_html.path "/orders" "/orders"

Ie, it just duplicates the path string to use as two separate format strings with different types for parsing and printing. If you need to actually have a different format string for printing (eg if you need to print the path with query parameters), you can use the underlying Dream_html.path function directly: path "/orders/%s" "/orders/%s?utm_src=%s&utm_campaign=%s".

The PPX also has the benefit that it checks that the path is well-formed at compile time. If you pass in an invalid path you get a compile error:

  File "test/route_test.ml", line 1, characters 0-20:
  1 | let%path bad = "foo"
      ^^^^^^^^^^^^^^^^^^^^
  Error: Invalid path: 'foo'. Paths must start with a '/' character
  • since 3.9.0
OCaml

Innovation. Community. Security.