Trait HttpResource

Source
pub trait HttpResource<R: for<'de> Deserialize<'de>> {
    // Required method
    fn path(&self) -> String;

    // Provided methods
    fn method(&self) -> Method { ... }
    fn json(&self) -> Option<String> { ... }
    fn path_without_query(&self) -> String { ... }
}
Expand description

Represents an HTTP resource (endpoint)

This is used as a parameter to Scryfall in order to make a request to the api.

Required Methods§

Source

fn path(&self) -> String

Defines the path for the endpoint

The path should be relative to the base_url of Scryfall

Provided Methods§

Source

fn method(&self) -> Method

Defines the HTTP method for the endpoint

Source

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

Defines the (optional) json body when requesting the endpoint.

This is useful in cases of POST/PUT/PATCH etc. By default it is None.

Source

fn path_without_query(&self) -> String

Strips the query parameters (if any) from the endpoint path

§Example
use scryfall_sdk_rust::HttpResource;
 
struct SomeResource;
impl HttpResource<String> for SomeResource {
    fn path(&self) -> String {
        "somepath?aQueryParam=123".into()
    }
}

let res = SomeResource;
assert_eq!("somepath", res.path_without_query())

Implementors§