File: client1.ml

package info (click to toggle)
ocaml-cohttp 6.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,624 kB
  • sloc: ml: 13,107; makefile: 20; sh: 18; javascript: 18
file content (18 lines) | stat: -rw-r--r-- 642 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
open Cohttp_eio

let () = Logs.set_reporter (Logs_fmt.reporter ())

and () =
  (* The eio backend does not leverage domains yet, but might in the near future *)
  Logs_threaded.enable ()

and () = Logs.Src.set_level Cohttp_eio.src (Some Debug)

let () =
  Eio_main.run @@ fun env ->
  let client = Client.make ~https:None env#net in
  Eio.Switch.run @@ fun sw ->
  let resp, body = Client.get ~sw client (Uri.of_string "http://example.com") in
  if Http.Status.compare resp.status `OK = 0 then
    print_string @@ Eio.Buf_read.(parse_exn take_all) body ~max_size:max_int
  else Fmt.epr "Unexpected HTTP status: %a" Http.Status.pp resp.status