pub trait RestApiEndpoint {
type RequestBody;
// Required methods
fn method(&self) -> Result<Method, Error>;
fn url(&self, base_url: &Url) -> Result<Url, Error>;
fn request_body(&self) -> Result<Option<Cow<'_, Self::RequestBody>>, Error>
where Self::RequestBody: Clone + Serialize + Debug;
}Expand description
a trait for objects describing a REST API endpoint
this is implemented by types which contain all the necessary information for a request.
Required Associated Types§
Sourcetype RequestBody
type RequestBody
the type of the request body
Required Methods§
Sourcefn method(&self) -> Result<Method, Error>
fn method(&self) -> Result<Method, Error>
returns the HTTP method to use
since this is Icinga this is the method passed to X-HTTP-Method-Override
the actual HTTP method will always be POST if there is a request body
§Errors
this should return an error if something went wrong in determining the request method
Sourcefn url(&self, base_url: &Url) -> Result<Url, Error>
fn url(&self, base_url: &Url) -> Result<Url, Error>
returns the URL to use for the request based on the base URL passed in as a parameter
§Errors
this should return an error if something went wrong in determining the URL (e.g. parse error on the fragment joined to the base URL)
Sourcefn request_body(&self) -> Result<Option<Cow<'_, Self::RequestBody>>, Error>
fn request_body(&self) -> Result<Option<Cow<'_, Self::RequestBody>>, Error>
the request body which must be a JSON serializable type
since it is always JSON we do not need to return a Content-Type
§Errors
this should return an error if something went wrong in determining the request body
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".