Trait Endpoint

Source
pub trait Endpoint {
    type Response: for<'a> Deserialize<'a> + Debug;

    // Required methods
    fn method(&self) -> Method;
    fn path(&self) -> String;

    // Provided methods
    fn query(&self) -> Option<String> { ... }
    fn headers(&self) -> Option<HeaderMap> { ... }
    fn body(&self) -> Option<String> { ... }
    fn url(&self, base_url: &Url) -> Url { ... }
    fn content_type(&self) -> Cow<'static, str> { ... }
}
Expand description

Represents a specification for an API call that can be built into an HTTP request and sent. New endpoints should implement this trait.

If the request succeeds, the call will resolve to a Response.

Required Associated Types§

Source

type Response: for<'a> Deserialize<'a> + Debug

Required Methods§

Source

fn method(&self) -> Method

The HTTP Method used for this endpoint (e.g. GET, PATCH, DELETE)

Source

fn path(&self) -> String

The relative URL path for this endpoint

Provided Methods§

Source

fn query(&self) -> Option<String>

The url-encoded query string associated with this endpoint. Defaults to None.

Implementors should inline this.

Source

fn headers(&self) -> Option<HeaderMap>

The set of headers to be sent with request. Defaults to None.

Implementors should inline this.

Source

fn body(&self) -> Option<String>

The HTTP body associated with this endpoint. If not implemented, defaults to None.

Implementors should inline this.

Source

fn url(&self, base_url: &Url) -> Url

Builds and returns a formatted full URL, including query, for the endpoint.

Implementors should generally not override this.

Source

fn content_type(&self) -> Cow<'static, str>

If body is populated, indicates the body MIME type (defaults to JSON).

Implementors generally do not need to override this.

Implementors§