package http-mirage-client

  1. Overview
  2. Docs
HTTP client for MirageOS

Install

Dune Dependency

Authors

Maintainers

Sources

http-mirage-client-0.0.2.tbz
sha256=b2da26d77b772a7d5e86479445e9b7f66c617772e6973f33f66ded1c6729e6f6
sha512=ded431f66c69340cfd7c67b531e54b072ea19a733ea47e6926e1426a5dc75ac42916cc3466be74558351f92a02b745aa43e82442d9d1744f7131743e7e332218

Description

Published: 02 Feb 2023

README

An HTTP (http/1.1 or h2) client for MirageOS

This little library provides an HTTP client which can be usable inside a unikernel/MirageOS. It follows the same API as http-lwt-client which is pretty simple and uses:

This library wants to be easy to use and it is associated to a MirageOS device in order to facilite functoria to compose everything (mainly the TCP/IP stack) according to the user's target and give a witness so as to be able to allocate a new connection to a peer and process the HTTP flow.

How to use it?

First, you need to describe a new http_client device:

open Mirage

type http_client = HTTP_client
let http_client = typ HTTP_client

let http_client =
  let connect _ modname = function
    | [ _pclock; _tcpv4v6; ctx ] ->
      Fmt.str {ocaml|%s.connect %s|ocaml} modname ctx
    | _ -> assert false in
  impl ~connect "Http_mirage_client.Make"
    (pclock @-> tcpv4v6 @-> git_client @-> http_client)

Then, you can decide how to construct such device:

let stack = generic_stackv4v6 default_network
let dns   = generic_dns_client stack
let tcp   = tcpv4v6_of_stackv4v6 stack

let http_client =
  (* XXX(dinosaure): it seems unconventional to use [git_happy_eyeballs] here
     when we want to do HTTP requests only. The name was not so good and we
     will fix that into the next release of the mirage tool. But structurally,
     you don't bring anything related to Git. It's just a bad choice of name. *)
  let happy_eyeballs = git_happy_eyeballs stack dns
    (generic_happy_eyeballs stack dns) in
  http_client $ default_posix_clock $ tcp $ happy_eyeballs

Finally, you can use the witness into your unikernel.ml:

open Lwt.Infix

module Make (HTTP_client : Http_mirage_client.S) = struct
  let start http_client =
    let body_f _response acc data = Lwt.return (acc ^ data) in
    Http_mirage_client.one_request http_client "https://mirage.io/" body_f ""
    >>= function
    | Ok (resp, body) -> ...
    | Error _ -> ...
end

Dependencies (10)

  1. h2 >= "0.9.0" & < "0.10.0"
  2. httpaf
  3. mimic-happy-eyeballs
  4. lwt >= "5.5.0"
  5. tcpip >= "7.0.0"
  6. mirage-time >= "3.0.0"
  7. mirage-clock >= "4.0.0"
  8. paf >= "0.2.0"
  9. ocaml >= "4.11.0"
  10. dune >= "2.3"

Dev Dependencies (5)

  1. mirage-time-unix with-test
  2. mirage-random-stdlib with-test
  3. mirage-clock-unix with-test
  4. mirage-entropy with-test & >= "0.5.0"
  5. alcotest-lwt with-test

Conflicts

None

OCaml

Innovation. Community. Security.