Here's a simple example of using the library Cohttp:
open Lwt
open Cohttp
open Cohttp_lwt_unix
let body =
Client.get (Uri.of_string "http://www.reddit.com/") >>= fun (resp, body) ->
let code = resp |> Response.status |> Code.code_of_status in
Printf.printf "Response code: %d\n" code;
Printf.printf "Headers: %s\n" (resp |> Response.headers |> Header.to_string);
body |> Cohttp_lwt.Body.to_string >|= fun body ->
Printf.printf "Body of length: %d\n" (String.length body);
body
let () =
let body = Lwt_main.run body in
print_endline ("Received body\n" ^ body)
I'm trying to compile it
ocaml my_test1.ml
Error:
Error: Unbound module Lwt
How to actually include/require the module Lwt into my app?
update
Also:
$ ocamlbuild
bash: ocamlbuild: command not found
But:
$ opam install ocamlbuild
[NOTE] Package ocamlbuild is already installed (current version is
0.12.0).
And
$ opam install ocamlfind
[NOTE] Package ocamlfind is already installed (current version is
1.7.3-1).
And
$ ocamlfind
bash: ocamlfind: command not found
Where are ocamlfind and ocamlbuild located?
update2
$ ocamlfind ocamlc -package lwt -c my_test1.ml
File "my_test1.ml", line 2, characters 5-11:
Error: Unbound module Cohttp