Struct http_api_problem::HttpApiProblem [] [src]

pub struct HttpApiProblem {
    pub type_url: Option<String>,
    pub status: Option<HttpStatusCode>,
    pub title: String,
    pub detail: Option<String>,
    pub instance: Option<String>,
}

Description of a problem that can be returned by an HTTP API based on RFC7807

Example

{
   "type": "https://example.com/probs/out-of-credit",
   "title": "You do not have enough credit.",
   "detail": "Your current balance is 30, but that costs 50.",
   "instance": "/account/12345/msgs/abc",
}

Fields

A URI reference RFC3986 that identifies the problem type. This specification encourages that, when dereferenced, it provide human-readable documentation for the problem type (e.g., using HTML [W3C.REC-html5-20141028]). When this member is not present, its value is assumed to be "about:blank".

The HTTP status code RFC7231, Section 6 generated by the origin server for this occurrence of the problem.

A short, human-readable summary of the problem type. It SHOULD NOT change from occurrence to occurrence of the problem, except for purposes of localization (e.g., using proactive content negotiation; see RFC7231, Section 3.4.

This is the only mandatory field.

A human-readable explanation specific to this occurrence of the problem.

A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced.

Methods

impl HttpApiProblem
[src]

[src]

Creates a new instance with the given title.

Example

use http_api_problem::*;

let p = HttpApiProblem::new("Internal Error");

assert_eq!(None, p.type_url);
assert_eq!(None, p.status);
assert_eq!("Internal Error", p.title);
assert_eq!(None, p.detail);
assert_eq!(None, p.instance);

[src]

Creates a new instance with the title and type_url derived from the status.

Example

use http_api_problem::*;

let p = HttpApiProblem::with_title_and_type_from_status(503);

assert_eq!(Some("https://httpstatuses.com/503".to_string()), p.type_url);
assert_eq!(Some(HttpStatusCode::ServiceUnavailable), p.status);
assert_eq!("Service Unavailable", &p.title);
assert_eq!(None, p.detail);
assert_eq!(None, p.instance);

[src]

Creates a new instance with title derived from status.

Example

use http_api_problem::*;

let p = HttpApiProblem::with_title_from_status(404);

assert_eq!(None, p.type_url);
assert_eq!(Some(HttpStatusCode::NotFound), p.status);
assert_eq!("Not Found", p.title);
assert_eq!(None, p.detail);
assert_eq!(None, p.instance);

[src]

Sets the type_url

Example

use http_api_problem::*;

let p =
    HttpApiProblem::new("Error")
    .set_type_url("http://example.com/my/real_error");

assert_eq!(Some("http://example.com/my/real_error".to_string()), p.type_url);
assert_eq!(None, p.status);
assert_eq!("Error", p.title);
assert_eq!(None, p.detail);
assert_eq!(None, p.instance);

[src]

Sets the status

Example

use http_api_problem::*;

let p = HttpApiProblem::new("Error").set_status(404);

assert_eq!(None, p.type_url);
assert_eq!(Some(HttpStatusCode::NotFound), p.status);
assert_eq!("Error", p.title);
assert_eq!(None, p.detail);
assert_eq!(None, p.instance);

[src]

Sets the title

Example

use http_api_problem::*;

let p = HttpApiProblem::new("Error").set_title("Another Error");

assert_eq!(None, p.type_url);
assert_eq!(None, p.status);
assert_eq!("Another Error", p.title);
assert_eq!(None, p.detail);
assert_eq!(None, p.instance);

[src]

Sets the detail

Example

use http_api_problem::*;

let p =
    HttpApiProblem::new("Error")
    .set_detail("a detailed description");

assert_eq!(None, p.type_url);
assert_eq!(None, p.status);
assert_eq!("Error", p.title);
assert_eq!(Some("a detailed description".to_string()), p.detail);
assert_eq!(None, p.instance);

[src]

Sets the instance

Example

use http_api_problem::*;

let p =
    HttpApiProblem::new("Error")
    .set_instance("/account/1234/withdraw");

assert_eq!(None, p.type_url);
assert_eq!(None, p.status);
assert_eq!("Error", p.title);
assert_eq!(None, p.detail);
assert_eq!(Some("/account/1234/withdraw".to_string()), p.instance);

Trait Implementations

impl Debug for HttpApiProblem
[src]

[src]

Formats the value using the given formatter.

impl Clone for HttpApiProblem
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl From<HttpStatusCode> for HttpApiProblem
[src]

[src]

Performs the conversion.