cdumay_http 0.1.1

A Rust Library for HTTP data
Documentation
  • Coverage
  • 100%
    52 out of 52 items documented1 out of 1 items with examples
  • Size
  • Source code size: 19.87 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 18.98 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 33s Average build duration of successful builds.
  • all releases: 33s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • cdumay/cdumay_http
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • cdumay

cdumay_http

License: BSD-3-Clause cdumay_http on crates.io cdumay_http on docs.rs Source Code Repository

This crate provides structured mapping from HTTP status codes to custom application including error types using the cdumay_core crate. It is especially useful when you want to handle HTTP error responses in a standardized and extensible way.

Features

  • Maps common HTTP status codes (300–511) to well-defined application-specific errors.
  • Integrates seamlessly with the cdumay_core ecosystem.
  • Allows contextual error data and custom messages.
  • Supports conversion from u16

Usage

Define Error Kinds and Errors

The define_kinds! macro associates each HTTP status code with:

  • A numerical HTTP status code
  • A descriptive error label

The define_errors! macro maps those kinds into named error types (e.g., NotFound, TooManyRequests, etc.).

use std::collections::BTreeMap;
use serde_value::Value;
use cdumay_http::HTTPErrorConverter;

let mut context = BTreeMap::new();
context.insert("url".to_string(), Value::String("https://example.com".to_string()));

let error = HTTPErrorConverter::from_u16(404, context);
println!("{:?}", error);