Trait noir::HttpEndpoint
[−]
[src]
pub trait HttpEndpoint: Send + Copy { fn hostname(&self) -> &'static str; fn port(&self) -> u16; fn host(&self) -> String { ... } fn protocol(&self) -> &'static str { ... } fn url(&self) -> String { ... } fn url_with_path(&self, path: &str) -> String { ... } fn options(&self, path: &'static str) -> HttpResponse<Self> { ... } fn get(&self, path: &'static str) -> HttpResponse<Self> { ... } fn post(&self, path: &'static str) -> HttpResponse<Self> { ... } fn put(&self, path: &'static str) -> HttpResponse<Self> { ... } fn delete(&self, path: &'static str) -> HttpResponse<Self> { ... } fn head(&self, path: &'static str) -> HttpResponse<Self> { ... } fn trace(&self, path: &'static str) -> HttpResponse<Self> { ... } fn connect(&self, path: &'static str) -> HttpResponse<Self> { ... } fn patch(&self, path: &'static str) -> HttpResponse<Self> { ... } fn ext(&self, http_verb: &'static str, path: &'static str) -> HttpResponse<Self> { ... } }
A trait for the description of a HTTP based endpoint used to provided mocked responses to a testable API.
Example Implementation
use noir::HttpEndpoint; #[derive(Copy, Clone)] struct ExternalResource; impl HttpEndpoint for ExternalResource { fn hostname(&self) -> &'static str { "rust-lang.org" } fn port(&self) -> u16 { 443 } }
Required Methods
fn hostname(&self) -> &'static str
Returns the hostname of the endpoint.
fn port(&self) -> u16
Returns the port of the api.
Provided Methods
fn host(&self) -> String
Returns the hostname:port
combination of the endpoint.
fn protocol(&self) -> &'static str
Returns the http protocol used by the endpoint.
By default this is based on the port, returning https
for port 443.
fn url(&self) -> String
Returns the fully qualified base url of the endpoint.
fn url_with_path(&self, path: &str) -> String
Returns the fully qualified url of the endpoint with the specified path
appended.
fn options(&self, path: &'static str) -> HttpResponse<Self>
Return a response to the next OPTIONS
request made against the endpoint
which matches the specified path.
fn get(&self, path: &'static str) -> HttpResponse<Self>
Return a response to the next GET
request made against the endpoint
which matches the specified path.
fn post(&self, path: &'static str) -> HttpResponse<Self>
Return a response to the next POST
request made against the endpoint
which matches the specified path.
fn put(&self, path: &'static str) -> HttpResponse<Self>
Return a response to the next PUT
request made against the endpoint
which matches the specified path.
fn delete(&self, path: &'static str) -> HttpResponse<Self>
Return a response to the next DELETE
request made against the endpoint
which matches the specified path.
fn head(&self, path: &'static str) -> HttpResponse<Self>
Return a response to the next HEAD
request made against the endpoint
which matches the specified path.
fn trace(&self, path: &'static str) -> HttpResponse<Self>
Return a response to the next TRACE
request made against the endpoint
which matches the specified path.
fn connect(&self, path: &'static str) -> HttpResponse<Self>
Return a response to the next CONNECT
request made against the endpoint
which matches the specified path.
fn patch(&self, path: &'static str) -> HttpResponse<Self>
Return a response to the next PATCH
request made against the endpoint
which matches the specified path.
fn ext(&self, http_verb: &'static str, path: &'static str) -> HttpResponse<Self>
Return a response to the next request made against the endpoint which matches the specified path and HTTP verb extension.