problem_details
RFC 9457 / RFC 7807 problem details for HTTP APIs.
This crate can be used to represent a problem details object as defined in RFC 9457 (which obsoletes RFC 7807).
The [ProblemDetails] struct includes the standard fields
(type, status,
title, detail,
instance),
as well as type-safe custom extensions.
Extensions
To add extensions, you need to define a struct that holds the extension
fields, and use this struct as the generic parameter for [ProblemDetails<Ext>].
Using with_extensions, the type is adjusted
automatically for you.
Extension fields are flattened into the problem details object when serialized.
use ProblemDetails;
let details = new
.with_extensions;
// details is of type ProblemDetails<MyExt>
let typecheck: = details;
If you need dynamic extensions, you can use a HashMap
as extensions object.
use HashMap;
use ProblemDetails;
let mut extensions = new;
extensions.insert;
extensions.insert;
let details = new
.with_extensions;
// details is of type ProblemDetails<HashMap<String, serde_json::Value>>
let typecheck: = details;
Example
The following example shows how to create a problem details object that produces the example JSON from the RFC.
use Uri;
use ProblemDetails;
let details = new
.with_type
.with_title
.with_detail
.with_instance
.with_extensions;
let json = to_value.unwrap;
assert_eq!;
Features
- serde: Enables serde support for the
ProblemDetailsstruct (enabled by default)
Caveats
This crate is not fully compliant with the RFC, because it fails to deserialize json values containing properties with incorrect types (required by Chapter 3.1 of the RFC).
License: MIT OR Apache-2.0