Skip to content
AlphaJackPublic

About

honig turns an OpenAPI description into typed Rust clients and servers.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

honig

honig turns an OpenAPI description into typed Rust clients and servers.

It is meant for spec-first workflow and catches drift from the OpenAPI description at compile time.

It supports OpenAPI 3.2 and earlier, focusing on both correctness and runtime performance.

Install

honig installs as a pre-built binary with cargo-binstall:

cargo binstall cargo-honig

Getting started

Three commands add honig to your crate:

cargo honig init path/to/openapi.yaml
cargo add honig@=x.y.z -F client,server
cargo honig generate

init adds the [package.metadata.honig.api] section to your Cargo.toml and prints the exact cargo add lines. generate writes the module to src/api. It never edits Cargo.toml. When the code needs a honig feature that is off, generate stops and prints the cargo add line that turns it on.

Then you can declare the module in src/lib.rs or src/main.rs:

pub mod api;

The book's recipes build whole setups: a server and its client, a web app next to its API, auth from a layer that you already run, and a full middleware stack.

Update the API

cargo honig generate updates the module after every change to the description. Every place your code must change becomes a compile error: a new operation is a missing method, a new response is a missing match arm.

Run cargo honig check in CI to assert that the module is up to date with the description or the generator.

Update honig

Install the new generator, then generate again:

cargo binstall cargo-honig
cargo honig generate

generate moves the honig dependency to the version of the generator. The two always match: the generated code calls runtime internals that change between versions.

Full documentation

The book covers usage and features.

About

honig turns an OpenAPI description into typed Rust clients and servers.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages