Advertisement
Guest User

Untitled

a guest
Apr 15th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.65 KB | None | 0 0
  1. (* test.ml *)
  2.  
  3. open Lwt
  4. open Cohttp
  5. open Cohttp_lwt_unix
  6.  
  7. open Core.Std
  8.  
  9. let server =
  10.   let callback _conn req body =
  11.     let uri = req |> Request.uri |> Uri.to_string in
  12.     let meth = req |> Request.meth |> Code.string_of_method in
  13.     let headers = req |> Request.headers |> Header.to_string in
  14.     body |> Cohttp_lwt_body.to_string >|= (fun body ->
  15.       (Printf.sprintf "Uri: %s\nMethod: %s\nHeaders\nHeaders: %s\nBody: %s"
  16.          uri meth headers body))
  17.     >>= (fun body -> Server.respond_string ~status:`OK ~body ())
  18.   in
  19.   Server.create ~mode:(`TCP (`Port 8000)) (Server.make ~callback ())
  20.  
  21. (*
  22. let () = ignore (Lwt_main.run server)
  23.  *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement