HTTP types: headers, status codes, methods, bodies, MIME types
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

OCaml 98.6%
Python 0.7%
Dune 0.1%
Shell 0.1%
Other 0.5%
42 1 0

Clone this repository

https://tangled.org/gazagnaire.org/ocaml-http https://tangled.org/did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-http
git@git.recoil.org:gazagnaire.org/ocaml-http git@git.recoil.org:did:plc:jhift2vwcxhou52p3sewcrpx/ocaml-http

For self-hosted knots, clone URLs may differ based on your setup.

Download tar.gz
README.md

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 names
  • Status -- HTTP status codes (1xx--5xx) per RFC 9110
  • Method -- HTTP methods (GET, POST, PUT, DELETE, ...)
  • Response -- HTTP response with status, headers, and streaming body
  • Mime -- MIME type detection and constants
  • Cache_control -- cache directive parsing per RFC 9111
  • Huri -- efficient URI serialization to Eio.Buf_write
  • Error -- centralized error types and Eio.Io exception integration
  • Header_name -- type-safe HTTP header names
  • Http_date -- HTTP-date parsing per RFC 9110
  • Http_version -- HTTP protocol version types and ALPN
  • Expect_continue -- HTTP 100-Continue configuration
  • Response_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