expression

REST: classify errors by type rather than prose

A problem type is the stable machine-readable identity of an error category. Human-readable text can change or be localized. Unknown extensions must be ignored by problem-detail consumers; the actual HTTP status still controls HTTP semantics. This example only parses synthetic bodies. Standalone synthetic example. Expected stdout (not executed): quantity error: true quantity error: true Common mistake: Comparing localized error titles to determine program control flow.

Formal Syntax & Structure

rust syntaxrust
problem["type"]

Working Example

Example Snippetrust
use axum::{Router, Json, body::{Body, to_bytes}, http::{Request, StatusCode}};use serde::{Deserialize, Serialize};use tower::ServiceExt;
#[tokio::main(flavor = "current_thread")]async fn main() {    #[derive(Deserialize)]    struct Problem { #[serde(rename = "type")] kind: String }    for body in [r#"{"type":"https://api.example.invalid/problems/quantity","title":"Invalid quantity"}"#, r#"{"type":"https://api.example.invalid/problems/quantity","title":"Check quantity","extra":true}"#] {        let p: Problem = serde_json::from_str(body).unwrap();        println!("quantity error: {}", p.kind == "https://api.example.invalid/problems/quantity");    }}
Rust Reference