Endpoint

Trait Endpoint 

Source
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§

Source

type Input

The type of data being passed in as part of a request to this endpoint.

Source

type Output

The type of data being returned in the response from this endpoint.

Source

type Error: Error + From<HttpError> + From<Self::ConversionError> + 'static

The type of error this endpoint can report.

Source

type ConversionError: Error

An error emitted when converting between formats.

Source

type ApiError: Error

An error emitted by the API.

Required Methods§

Source

fn path(input: &Self::Input) -> Str

Inquire the path the request should go to.

Source

fn parse(body: &[u8]) -> Result<Self::Output, Self::ConversionError>

Parse the body into the final result.

Source

fn parse_err(body: &[u8]) -> Result<Self::ApiError, Vec<u8>>

Parse an API error.

Provided Methods§

Source

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.

Source

fn method() -> Method

Retrieve the HTTP method to use.

The default method being used is GET.

Source

fn query(input: &Self::Input) -> Result<Option<Str>, Self::ConversionError>

Inquire the query the request should use.

By default no query is emitted.

Source

fn headers( input: &Self::Input, ) -> Result<Option<HeaderMap>, Self::ConversionError>

Gather the request headers to set.

Source

fn body(input: &Self::Input) -> Result<Option<Bytes>, Self::ConversionError>

Retrieve the request’s body.

By default this method creates an empty body.

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.

Implementors§