Trait http_endpoint::Endpoint[][src]

pub trait Endpoint {
    type Input;
    type Output;
    type Error: Error + From<HttpError> + From<Self::ConversionError> + 'static;
    type ConversionError: Error;
    type ApiError: Error;
    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>>; 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.

Associated Types

type Input[src]

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

type Output[src]

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

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

The type of error this endpoint can report.

type ConversionError: Error[src]

An error emitted when converting between formats.

type ApiError: Error[src]

An error emitted by the API.

Required methods

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

Inquire the path the request should go to.

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

Parse the body into the final result.

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

Parse an API error.

Provided methods

fn base_url() -> Option<Str>[src]

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.

fn method() -> Method[src]

Retrieve the HTTP method to use.

The default method being used is GET.

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

Inquire the query the request should use.

By default no query is emitted.

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

Gather the request headers to set.

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

Retrieve the request’s body.

By default this method creates an empty body.

Implementors