http -- HTTP types for OCaml#
Core HTTP types: headers, status codes, methods, bodies, MIME types, and responses. This library provides the shared type definitions used by HTTP client and server libraries, following RFC 9110.
Built on Eio for streaming bodies and file I/O.
Installation#
Install with opam:
$ opam install nox-http
If opam cannot find the package, it may not yet be released in the public
opam-repository. Add the overlay repository, then install it:
$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install nox-http
Modules#
Body-- request body construction (string, JSON, form, multipart, file, stream)Headers-- case-insensitive header map with type-safe standard header namesStatus-- HTTP status codes (1xx--5xx) per RFC 9110Method-- HTTP methods (GET, POST, PUT, DELETE, ...)Response-- HTTP response with status, headers, and streaming bodyMime-- MIME type detection and constantsCache_control-- cache directive parsing per RFC 9111Huri-- efficient URI serialization toEio.Buf_writeError-- centralized error types and Eio.Io exception integrationHeader_name-- type-safe HTTP header namesHttp_date-- HTTP-date parsing per RFC 9110Http_version-- HTTP protocol version types and ALPNExpect_continue-- HTTP 100-Continue configurationResponse_limits-- configurable response size limits
Quick Start#
open Http
(* Build a JSON body. *)
let body =
Json.Value.(
Body.json (object' [ member (name "name") (string "Alice") ]))
(* Build headers. *)
let headers =
Headers.empty
|> Headers.set `Content_type "application/json"
|> Headers.set `Authorization "Bearer token"
|> Headers.set (`Other "X-Request-Id") "abc123"
(* Multipart file upload. *)
let upload ~fs =
Body.multipart
[
{
Body.name = "file";
filename = Some "doc.pdf";
content_type = Mime.of_string "application/pdf";
content = `File Eio.Path.(fs / "doc.pdf");
};
]
License#
ISC