http-api-problem
A Rust library for building RFC 7807 problem+json HTTP error responses for APIs.
Repository Health
Technical Analysis
http-api-problem is a small Rust library for producing machine-readable HTTP error responses that conform to RFC 7807 (Problem Details for HTTP APIs). It centers on an HttpApiProblem type with a fluent builder for setting the status, title, detail, type URL, and instance of a problem.
The type serializes to and from the standard application/problem+json media type via serde, and optional feature flags provide first-class integrations with popular web frameworks including actix-web, axum, warp, rocket, salvo, tide, and hyper so returning a well-formed problem response fits naturally into each framework’s handlers.
What You Get
- An
HttpApiProblemtype with a chainable builder for status, title, detail, type URL, and instance - serde
Serialize/Deserializeproducing theapplication/problem+jsonrepresentation - Optional integrations for actix-web, axum, warp, rocket, salvo, tide, and hyper
- An
ApiErrortype and derive macro (via theapi-errorfeature) for richer error handling - Optional JSON Schema generation through the
schemars-basedjson-schemafeature
Common Use Cases
- Returning consistent, standards-based error bodies from a Rust HTTP API
- Mapping internal errors into problem+json responses inside a web framework handler
- Sharing a documented, self-describing error contract with API consumers
Under The Hood
Architecture — The crate is deliberately small. src/lib.rs defines the HttpApiProblem struct with optional status, title, detail, type_url, and instance fields plus a builder-style API, and derives serde Serialize/Deserialize to emit application/problem+json. src/api_error.rs layers a richer ApiError abstraction (gated by the api-error feature) on top, and framework conversions are compiled in only when the corresponding feature flag is enabled. src/test.rs holds the test suite.
Tech Stack — Rust (edition 2021) built on serde, serde_json, and the http crate for status codes. Every web-framework dependency (hyper, actix-web, axum-core, warp, rocket, salvo, tide) is optional and behind a feature flag, and a companion http-api-problem-derive proc-macro crate lives in the workspace for the api-error feature.
Code Quality — Idiomatic, focused Rust with an ergonomic fluent builder and thorough rustdoc examples that double as doc-tests. Tests live in src/test.rs; the codebase is compact (a couple of source files, ~59 KB of Rust) and easy to audit, though the project has seen little recent activity.
API Design — The public surface is minimal and discoverable: HttpApiProblem::new(status).title(..).detail(..).type_url(..).instance(..), plus try_new(u16) for dynamic status codes. Feature-gated From/IntoResponse conversions mean adopting it in an existing framework usually costs a single import and one enum arm, keeping boilerplate low.