Installation
httpz requires the OxCaml compiler, which extends OCaml 5.2+ with unboxed types. This guide walks you through installing OxCaml and setting up httpz in your project.Prerequisites
Before installing httpz, you need:- OCaml 5.2 or later (as the base for OxCaml)
- opam 2.0+ (OCaml package manager)
- dune 3.20+ (build system)
Step 1: Install OxCaml
OxCaml is a modified OCaml compiler that adds support for unboxed types.Get OxCaml
Visit the official OxCaml website to download and install the compiler:OxCaml provides unboxed primitives (
int16#, int64#, char#), unboxed records (#{...}), and local allocations (@ local) that are essential for httpz’s zero-allocation design.Verify Installation
After installing OxCaml, verify it’s working:Step 2: Install httpz via opam
As of this writing, httpz may not be in the main opam repository. Check the GitHub repository for the latest installation method.
From opam (when available)
From Source
To install from source:Step 3: Add to Your Project
Once httpz is installed, add it to your dune project.Update dune File
Addhttpz to your library or executable dependencies:
Update dune-project
Ensure yourdune-project specifies the minimum dune version:
Dependencies
httpz has the following runtime dependencies:Required Dependencies
- ocaml (>= 5.2) - Base OCaml/OxCaml compiler
- base - Jane Street’s standard library replacement
- base_bigstring - Bigarray-based strings for zero-copy I/O
- dune (>= 3.20) - Build system
Optional Dependencies (for server/examples)
- core (>= v0.17) - Extended standard library
- core_unix (>= v0.17) - Unix system calls
- async (>= v0.17) - Asynchronous programming library
- async_unix (>= v0.17) - Async Unix I/O
Test Dependencies
- core_bench - Benchmarking framework
- eio - Effects-based I/O library (for comparison benchmarks)
- eio_main - Eio main event loop
- ppx_jane - PPX rewriters
Configuration
OxCaml Compiler Requirements
httpz uses OxCaml-specific features:- Unboxed integers:
int16#,int64#,char# - Unboxed records:
#{ field : type }syntax - Local allocations:
@ localannotation - Exclave functions:
exclave_keyword for stack discipline
Build Configuration
If you’re building a project with httpz, your.ocamlformat should be compatible:
Verify Installation
Create a simple test file to verify httpz is working:test_httpz.ml
Running the Static File Server
Once installed, you can try the included static file server:The static file server demonstrates httpz’s capabilities including:
- Zero-copy bigstring I/O
- Range request support
- ETag-based caching
- Concurrent connection handling (up to 10,000 connections)
Troubleshooting
Unboxed Type Errors
If you see errors about unboxed types not being recognized:Missing Dependencies
If build fails with missing libraries:Dune Version Too Old
If you see dune compatibility errors:Next Steps
Quick Start
Learn how to parse HTTP requests with zero allocations