Skip to content

CoHTTP integration

ocaml
open Lwt.Infix
open Cohttp_lwt_unix

let () =
  let uri = Uri.of_string "https://api.apitube.io/v1/news/everything?limit=50&api_key=YOUR_API_KEY" in
  Client.get uri >>= fun (resp, body) ->
  match Cohttp.Response.status resp with
  | `OK -> body |> Cohttp_lwt.Body.to_string >|= print_endline
  | _ -> Lwt_io.printf "Error: %d\n" (Cohttp.Code.code_of_status (Cohttp.Response.status resp))
  |> Lwt_main.run