doc: fix examples

This commit is contained in:
Simon Cruanes 2020-12-08 00:24:55 -05:00
parent 697dc6c302
commit 70f1205880
2 changed files with 5 additions and 4 deletions

View file

@ -20,11 +20,11 @@ let () =
(* say hello *) (* say hello *)
S.add_route_handler ~meth:`GET server S.add_route_handler ~meth:`GET server
S.Route.(exact "hello" @/ string @/ return) S.Route.(exact "hello" @/ string @/ return)
(fun name _req -> S.Response.make_ok ("hello " ^name ^"!\n")); (fun name _req -> S.Response.make_string (Ok ("hello " ^name ^"!\n")));
(* echo request *) (* echo request *)
S.add_route_handler server S.add_route_handler server
S.Route.(exact "echo" @/ return) S.Route.(exact "echo" @/ return)
(fun req -> S.Response.make_ok (Format.asprintf "echo:@ %a@." S.Request.pp req)); (fun req -> S.Response.make_string (Ok (Format.asprintf "echo:@ %a@." S.Request.pp req)));
Printf.printf "listening on http://%s:%d\n%!" (S.addr server) (S.port server); Printf.printf "listening on http://%s:%d\n%!" (S.addr server) (S.port server);
match S.run server with match S.run server with
| Ok () -> () | Ok () -> ()

View file

@ -18,11 +18,12 @@ let () =
(* say hello *) (* say hello *)
S.add_route_handler ~meth:`GET server S.add_route_handler ~meth:`GET server
S.Route.(exact "hello" @/ string @/ return) S.Route.(exact "hello" @/ string @/ return)
(fun name _req -> S.Response.make_ok ("hello " ^name ^"!\n")); (fun name _req -> S.Response.make_string (Ok ("hello " ^name ^"!\n")));
(* echo request *) (* echo request *)
S.add_route_handler server S.add_route_handler server
S.Route.(exact "echo" @/ return) S.Route.(exact "echo" @/ return)
(fun req -> S.Response.make_ok (Format.asprintf "echo:@ %a@." S.Request.pp req)); (fun req -> S.Response.make_string
(Ok (Format.asprintf "echo:@ %a@." S.Request.pp req)));
S.add_route_handler ~meth:`PUT server S.add_route_handler ~meth:`PUT server
S.Route.(exact "upload" @/ string_urlencoded @/ return) S.Route.(exact "upload" @/ string_urlencoded @/ return)
(fun path req -> (fun path req ->