Skip to content

Instantly share code, notes, and snippets.

@iwilsonq
Last active March 23, 2019 21:57
Show Gist options
  • Save iwilsonq/0fd6c76319ea458b86917562fac3fed3 to your computer and use it in GitHub Desktop.
Save iwilsonq/0fd6c76319ea458b86917562fac3fed3 to your computer and use it in GitHub Desktop.
open Lwt;
open Cohttp;
open Cohttp_lwt_unix;
let body = 
 Client.get(Uri.of_string("https://ianwilson.io/")) >>= (resp, body) => {
let code = resp |> Response.status |> Code.code_of_status;
let headers = resp |> Response.headers |> Header.to_string;
Printf.printf("Response code: %d\n", code);
Printf.printf("Headers: %s\n", headers);
body |> Cohttp_lwt.Body.to_string >|= (body) => {
Printf.printf("Body of length: %d\n", (String.length(body));
body;
}
 }
let () = {
 let body = Lwt_main.run(body);
 print_endline("Received body \n" ++ body);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment