[−][src]Struct http_api_problem::HttpApiProblem
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
type_url: Option<String>
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".
status: Option<StatusCode>
The HTTP status code RFC7231, Section 6 generated by the origin server for this occurrence of the problem.
title: String
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.
detail: Option<String>
A human-readable explanation specific to this occurrence of the problem.
instance: Option<String>
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]
pub fn new<T: Into<String>>(title: T) -> HttpApiProblem
[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);
pub fn with_title_and_type_from_status<T: Into<StatusCode>>(
status: T
) -> HttpApiProblem
[src]
status: T
) -> HttpApiProblem
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(StatusCode::SERVICE_UNAVAILABLE); assert_eq!(Some("https://httpstatuses.com/503".to_string()), p.type_url); assert_eq!(Some(StatusCode::SERVICE_UNAVAILABLE), p.status); assert_eq!("Service Unavailable", &p.title); assert_eq!(None, p.detail); assert_eq!(None, p.instance);
pub fn with_title_from_status<T: Into<StatusCode>>(status: T) -> HttpApiProblem
[src]
Creates a new instance with title
derived from status
.
#Example
use http_api_problem::*; let p = HttpApiProblem::with_title_from_status(StatusCode::NOT_FOUND); assert_eq!(None, p.type_url); assert_eq!(Some(StatusCode::NOT_FOUND), p.status); assert_eq!("Not Found", p.title); assert_eq!(None, p.detail); assert_eq!(None, p.instance);
pub fn set_type_url<T: Into<String>>(self, type_url: T) -> HttpApiProblem
[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);
pub fn set_status<T: Into<StatusCode>>(self, status: T) -> HttpApiProblem
[src]
Sets the status
#Example
use http_api_problem::*; let p = HttpApiProblem::new("Error").set_status(StatusCode::NOT_FOUND); assert_eq!(None, p.type_url); assert_eq!(Some(StatusCode::NOT_FOUND), p.status); assert_eq!("Error", p.title); assert_eq!(None, p.detail); assert_eq!(None, p.instance);
pub fn set_title<T: Into<String>>(self, title: T) -> HttpApiProblem
[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);
pub fn set_detail<T: Into<String>>(self, detail: T) -> HttpApiProblem
[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);
pub fn set_value<K, V>(&mut self, key: K, value: &V) -> Result<(), String> where
V: Serialize,
K: Into<String>,
[src]
V: Serialize,
K: Into<String>,
Add a value that must be serializable. The key must not be one of the field names of this struct.
pub fn value<K, V>(&self, key: &str) -> Option<V> where
V: DeserializeOwned,
[src]
V: DeserializeOwned,
Returns the deserialized field for the given key.
If the key does not exist or the field is not deserializable to
the target type None
is returned
pub fn json_value(&self, key: &str) -> Option<&Value>
[src]
Returns the serde_json::Value
for the given key if the key exists.
pub fn keys<K, V>(
&self
) -> impl Iterator<Item = &String> where
V: DeserializeOwned,
[src]
&self
) -> impl Iterator<Item = &String> where
V: DeserializeOwned,
pub fn set_instance<T: Into<String>>(self, instance: T) -> HttpApiProblem
[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);
pub fn json_bytes(&self) -> Vec<u8>
[src]
Serialize to a JSON Vec<u8>
pub fn json_string(&self) -> String
[src]
Serialize to a JSON String
pub fn status_or_internal_server_error(&self) -> StatusCode
[src]
pub fn status_code_or_internal_server_error(&self) -> u16
[src]
Trait Implementations
impl Clone for HttpApiProblem
[src]
fn clone(&self) -> HttpApiProblem
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl From<StatusCode> for HttpApiProblem
[src]
fn from(status: StatusCode) -> HttpApiProblem
[src]
impl Debug for HttpApiProblem
[src]
impl Serialize for HttpApiProblem
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de> Deserialize<'de> for HttpApiProblem
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl Send for HttpApiProblem
impl Sync for HttpApiProblem
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,