mirror of
https://github.com/c-cube/tiny_httpd.git
synced 2025-12-07 19:55:36 -05:00
fix doc
This commit is contained in:
parent
3ac5510e2d
commit
13dca59afd
2 changed files with 11 additions and 10 deletions
|
|
@ -24,7 +24,7 @@ let () =
|
|||
(* echo request *)
|
||||
S.add_route_handler server
|
||||
S.Route.(exact "echo" @/ return)
|
||||
"/echo" (fun req -> S.Response.make_ok (Format.asprintf "echo:@ %a@." S.Request.pp req));
|
||||
(fun req -> S.Response.make_ok (Format.asprintf "echo:@ %a@." S.Request.pp req));
|
||||
Printf.printf "listening on http://%s:%d\n%!" (S.addr server) (S.port server);
|
||||
match S.run server with
|
||||
| Ok () -> ()
|
||||
|
|
|
|||
|
|
@ -16,15 +16,16 @@ module S = Tiny_httpd
|
|||
let () =
|
||||
let server = S.create () in
|
||||
(* say hello *)
|
||||
S.add_path_handler ~meth:`GET server
|
||||
"/hello/%s@/" (fun name _req ->
|
||||
S.Response.make_string (Ok ("hello " ^name ^"!\n")));
|
||||
S.add_route_handler ~meth:`GET server
|
||||
S.Route.(exact "hello" @/ string @/ return)
|
||||
(fun name _req -> S.Response.make_ok ("hello " ^name ^"!\n"));
|
||||
(* echo request *)
|
||||
S.add_path_handler server
|
||||
"/echo" (fun req -> S.Response.make_string
|
||||
(Ok (Format.asprintf "echo:@ %a@." S.Request.pp req)));
|
||||
S.add_path_handler ~meth:`PUT server
|
||||
"/upload/%s" (fun path req ->
|
||||
S.add_route_handler server
|
||||
S.Route.(exact "echo" @/ return)
|
||||
(fun req -> S.Response.make_ok (Format.asprintf "echo:@ %a@." S.Request.pp req));
|
||||
S.add_route_handler ~meth:`PUT server
|
||||
S.Route.(exact "upload" @/ string_urlencoded @/ return)
|
||||
(fun path req ->
|
||||
try
|
||||
let oc = open_out @@ "/tmp/" ^ path in
|
||||
output_string oc req.S.Request.body;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue