Skip to content

Instantly share code, notes, and snippets.

@abhi18av
Last active October 20, 2018 15:41
Show Gist options
  • Save abhi18av/563bbe3244b2cad16fa21c9377bfd6a6 to your computer and use it in GitHub Desktop.
Save abhi18av/563bbe3244b2cad16fa21c9377bfd6a6 to your computer and use it in GitHub Desktop.
(*
*
* http://deckofcardsapi.com/
*
*)
#require "lwt";;
#require "cohttp";;
#require "cohttp-lwt-unix";;
(* client_example.ml *)
open Lwt;;
open Cohttp;;
open Cohttp_lwt_unix;;
let body =
Client.get (Uri.of_string "https://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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment