Skip to content

Instantly share code, notes, and snippets.

@0xYUANTI
Created July 5, 2016 19:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xYUANTI/c4cfae56da20f0245e0778799d24a3ff to your computer and use it in GitHub Desktop.
Save 0xYUANTI/c4cfae56da20f0245e0778799d24a3ff to your computer and use it in GitHub Desktop.
/* example from cohttp readme, works with rebuild -pkg cohttp.lwt wtf.native */
open Lwt;
open Cohttp;
open Cohttp_lwt_unix;
let coroutine =
Client.get (Uri.of_string "http://www.reddit.com/") >>= fun (resp, body) => {
let code = resp |> Response.status |> Code.code_of_status;
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 x = Lwt_main.run coroutine;
print_endline ("Received body\n" ^ x);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment