Skip to content

Commit

Permalink
more fix to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tatchi committed Jun 14, 2024
1 parent 30f7743 commit 030b77e
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,21 @@ module Api = struct
| List_users : user list t [@GET "/"]
| Create_user : user t [@POST "/"]
| Get_user : { id : int } -> user t [@GET "/:id"]
| Raw : Dream.response t [@GET "/raw"]
| Raw : Ppx_deriving_router_runtime.response t [@GET "/raw"]
[@@deriving router]
end
```

Then handler can be defined as follows:
```ocaml
let return = Ppx_deriving_router_runtime.Return.return
let api_handle : Dream.handler =
let f : type a. a Api.t -> Dream.request -> a Lwt.t =
fun x _req ->
match x with
| List_users -> return []
| Create_user -> return { Api.id = 42 }
| Get_user { id } -> return { Api.id }
| Raw -> return (Dream.response "RAW")
| List_users -> Lwt.return []
| Create_user -> Lwt.return { Api.id = 42 }
| Get_user { id } -> Lwt.return { Api.id }
| Raw -> Dream.respond "RAW"
in
Api.handle { f }
```
Expand All @@ -199,6 +197,7 @@ It is possible to designate a route parameter to be a request body, in this
case, its value is decoded from the request body as JSON. The JSON decoder is
generated automatically for the route parameter type:
```ocaml
open Ppx_deriving_json_runtime.Primitives
type user_spec = { name : string } [@@deriving json]
type _ api =
| Create_user : {spec: user_spec; [@body]} -> int t [@POST]
Expand Down

0 comments on commit 030b77e

Please sign in to comment.