@@ -164,23 +164,21 @@ module Api = struct
164
164
| List_users : user list t [@GET "/"]
165
165
| Create_user : user t [@POST "/"]
166
166
| Get_user : { id : int } -> user t [@GET "/:id"]
167
- | Raw : Dream .response t [@GET "/raw"]
167
+ | Raw : Ppx_deriving_router_runtime .response t [@GET "/raw"]
168
168
[@@deriving router]
169
169
end
170
170
```
171
171
172
172
Then handler can be defined as follows:
173
173
``` ocaml
174
- let return = Ppx_deriving_router_runtime.Return.return
175
-
176
174
let api_handle : Dream.handler =
177
175
let f : type a. a Api.t -> Dream.request -> a Lwt.t =
178
176
fun x _req ->
179
177
match x with
180
- | List_users -> return []
181
- | Create_user -> return { Api.id = 42 }
182
- | Get_user { id } -> return { Api.id }
183
- | Raw -> return ( Dream.response "RAW")
178
+ | List_users -> Lwt. return []
179
+ | Create_user -> Lwt. return { Api.id = 42 }
180
+ | Get_user { id } -> Lwt. return { Api.id }
181
+ | Raw -> Dream.respond "RAW"
184
182
in
185
183
Api.handle { f }
186
184
```
@@ -199,6 +197,7 @@ It is possible to designate a route parameter to be a request body, in this
199
197
case, its value is decoded from the request body as JSON. The JSON decoder is
200
198
generated automatically for the route parameter type:
201
199
``` ocaml
200
+ open Ppx_deriving_json_runtime.Primitives
202
201
type user_spec = { name : string } [@@deriving json]
203
202
type _ api =
204
203
| Create_user : {spec: user_spec; [@body]} -> int t [@POST]
0 commit comments