pub trait Endpoint {
type Input;
type Output;
type Error: Error + From<HttpError> + From<Self::ConversionError> + 'static;
type ConversionError: Error;
type ApiError: Error;
// Required methods
fn path(input: &Self::Input) -> Str;
fn parse(body: &[u8]) -> Result<Self::Output, Self::ConversionError>;
fn parse_err(body: &[u8]) -> Result<Self::ApiError, Vec<u8>>;
// Provided methods
fn base_url() -> Option<Str> { ... }
fn method() -> Method { ... }
fn query(input: &Self::Input) -> Result<Option<Str>, Self::ConversionError> { ... }
fn headers(
input: &Self::Input,
) -> Result<Option<HeaderMap>, Self::ConversionError> { ... }
fn body(input: &Self::Input) -> Result<Option<Bytes>, Self::ConversionError> { ... }
}Expand description
A trait describing an HTTP endpoint.
An endpoint for our intents and purposes is basically a path and an
HTTP request method (e.g., GET or POST). The path will be combined
with an “authority” (scheme, host, and port) into a full URL. Query
parameters are supported as well.
An endpoint is used by the Trader who invokes the various methods.
Required Associated Types§
Sourcetype Error: Error + From<HttpError> + From<Self::ConversionError> + 'static
type Error: Error + From<HttpError> + From<Self::ConversionError> + 'static
The type of error this endpoint can report.
Sourcetype ConversionError: Error
type ConversionError: Error
An error emitted when converting between formats.
Required Methods§
Provided Methods§
Sourcefn base_url() -> Option<Str>
fn base_url() -> Option<Str>
Retrieve the base URL to use.
By default no URL is provided for the endpoint, in which case it is the client’s responsibility to supply one.
Sourcefn query(input: &Self::Input) -> Result<Option<Str>, Self::ConversionError>
fn query(input: &Self::Input) -> Result<Option<Str>, Self::ConversionError>
Inquire the query the request should use.
By default no query is emitted.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.