Last active
March 5, 2019 22:11
-
-
Save Leonidas-from-XIV/fb7739facfae5af9d8215a1b4d413818 to your computer and use it in GitHub Desktop.
A variant of https://pastebin.com/FNC2PMQP that works
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(executable | |
(name FNC2PMQP) | |
(public_name FNC2PMQP) | |
(libraries cohttp cohttp-lwt cohttp-lwt-unix lwt)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Lwt.Infix | |
open Cohttp | |
open Cohttp_lwt_unix | |
let body () = | |
Client.get (Uri.of_string "https://hacker-news.firebaseio.com/v0/maxitem.json") >>= fun (resp, body) -> | |
let code = resp |> Response.status |> Code.code_of_status in | |
Lwt_io.printf "Response Code: %d\n" code >>= fun () -> | |
Lwt_io.printf "Headers: %s\n" (resp |> Response.headers |> Header.to_string) >>= fun () -> | |
body |> Cohttp_lwt.Body.to_string >>= fun body -> | |
Lwt_io.printf "Body of length: %d\n" (String.length body) >|= fun () -> | |
body | |
let getItem item = | |
Client.get (Uri.of_string (String.concat "" ["https://hacker-news.firebaseio.com/v0/item/"; item; ".json?print=pretty"])) >>= fun (resp, body) -> | |
let code = resp |> Response.status |> Code.code_of_status in | |
Lwt_io.printf "Response Code: %d\n" code >>= fun () -> | |
body |> Cohttp_lwt.Body.to_string >|= fun body -> | |
body | |
let main () = | |
body () | |
>>= getItem | |
>>= Lwt_io.printf "Result: %s" | |
let () = | |
Lwt_main.run @@ main () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment