Crate problemdetails

source ·
Expand description

This crate provides an implementation of a Problem Details response for HTTP APIs, as defined in RFC-7807 / RFC-9457. This is a standard way for HTTP APIs to indicate that a problem occurred with the request, including some standard payload fields as required.

When used with a supported HTTP Server, this will automatically generate the correct JSON response and set the Content-Type header to the correct value of application/problem+json.

If used with an unsupported HTTP Server, the status code and body of the problem details can be extracted and sent manually. The body field is in the correct structure to format into JSON using something like serde already, so serializing it should be as simple as the HTTP Server allows for.


§Create an empty problem.


§Create a populated problem.

    .with_title("You do not have enough credit.")
    .with_detail("Your current balance is 30, but that costs 50.")
    .with_value("balance", 30)
    .with_value("accounts", vec!["/account/12345", "/account/67890"]);


HTTP Server support is behind feature flags for the appropriate HTTP Server. As such, you will need to enable the correct feature for the HTTP Server that you are using.

Currently supported features are:

  • axum - For the Axum HTTP Server.


  • Representation of a Problem error to return to the client.


  • Create a new Problem response to send to the client.

Type Aliases§

  • Result type where the error is always a Problem.