Skip to content

Commit

Permalink
fix example in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tatchi authored and andreypopp committed Jun 13, 2024
1 parent 6336e97 commit 52ed2c2
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,19 @@ val handle : (t -> Dream.request -> Dream.response Lwt.t) -> Dream.handler

is generated for each route type. Such function can be used to define a `Dream.handler`:
```ocaml
let return = Ppx_deriving_router_runtime.Return.return
let pages_handle = Pages.handle (fun route _req ->
match route with
| Home -> return (Dream.response "Home page!")
| About -> return (Dream.response "About page!")
| Hello {name; repeat} ->
let name =
match repeat with
| Some repeat ->
List.init repeat (fun _ -> name) |> String.concat ", "
| None -> name
in
return (Dream.response (Printf.sprintf "Hello, %s" name)))
let pages_handle =
Pages.handle (fun route _req ->
match route with
| Home -> Dream.respond "Home page!"
| About -> Dream.respond "About page!"
| Hello { name; repeat } ->
let name =
match repeat with
| Some repeat ->
List.init repeat (fun _ -> name) |> String.concat ", "
| None -> name
in
Dream.respond (Printf.sprintf "Hello, %s" name))
```

## Using the handler in a Dream app
Expand Down

0 comments on commit 52ed2c2

Please sign in to comment.