package dream-html

  1. Overview
  2. Docs
HTML generator eDSL for Dream

Install

Dune Dependency

Authors

Maintainers

Sources

dream-html-3.10.1.tbz
sha256=d9310e8c27e273392ae40eb1af572bd96eb410f37e6a6868808cdb9a7d3a7719
sha512=e1891a82657c9f994350e00ab2b6b86ec0904bef0fa1a17d93def089b62fd443a414a07c92b0d0adbde204b13d18fb4dea9fc6581ee02294c123bba6e1f7c816

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.