package dream-html
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=d1ac64685188a5b41834c8e1ffc4187f8dfdbc27a972898e6bb833ca4c715811
sha512=43ae60f49d3ada8cd633e0fbe6bf892094eb46a8f8ff1c7605c33724e6f44abcb3466dc61511994a8ac63a5ccd9421c53ce6f5f703bd307d9da3de7b6dbdf85e
doc/ppx/Ppx/index.html
Module Ppx
Source
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