Trait noir::HttpApi
[−]
[src]
pub trait HttpApi: Send + Copy + Default { fn start(&self); 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 timeout(&self) -> Duration { ... } fn options(path: &'static str) -> HttpRequest<Self> where Self: 'static { ... } fn get(path: &'static str) -> HttpRequest<Self> where Self: 'static { ... } fn post(path: &'static str) -> HttpRequest<Self> where Self: 'static { ... } fn put(path: &'static str) -> HttpRequest<Self> where Self: 'static { ... } fn delete(path: &'static str) -> HttpRequest<Self> where Self: 'static { ... } fn head(path: &'static str) -> HttpRequest<Self> where Self: 'static { ... } fn trace(path: &'static str) -> HttpRequest<Self> where Self: 'static { ... } fn connect(path: &'static str) -> HttpRequest<Self> where Self: 'static { ... } fn patch(path: &'static str) -> HttpRequest<Self> where Self: 'static { ... } fn ext(http_verb: &'static str, path: &'static str) -> HttpRequest<Self> where Self: 'static { ... } }
A trait for the description of a testable, HTTP based API.
Example Implementation
use noir::HttpApi; #[derive(Copy, Clone, Default)] struct Api; impl HttpApi for Api { fn hostname(&self) -> &'static str { "localhost" } fn port(&self) -> u16 { 8080 } fn start(&self) { // Start the HTTP server... } }
Test Failure Examples
From test_api_start_timeout
(Collapse)
From test_api_request_timeout
(Collapse)
Required Methods
fn start(&self)
A blocking callback for provision of the API.
The callback is executed in a background thread and should serve the API at the specified host.
fn hostname(&self) -> &'static str
Returns the hostname of the API.
fn port(&self) -> u16
Returns the port of the API.
Provided Methods
fn host(&self) -> String
Returns the hostname:port
combination of the API used for making
requests against the API.
fn protocol(&self) -> &'static str
Returns the HTTP protocol used by the API.
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 API.
fn url_with_path(&self, path: &str) -> String
Returns the fully qualified URL of the API with the specified path
appended.
fn timeout(&self) -> Duration
Should return the maximum duration to wait for the API to become available when a test is started.
Defaults to 1000ms
.
fn options(path: &'static str) -> HttpRequest<Self> where Self: 'static
Returns a OPTIONS
request that will be performed against the API.
fn get(path: &'static str) -> HttpRequest<Self> where Self: 'static
Returns a GET
request that will be performed against the API.
fn post(path: &'static str) -> HttpRequest<Self> where Self: 'static
Returns a POST
request that will be performed against the API.
fn put(path: &'static str) -> HttpRequest<Self> where Self: 'static
Returns a PUT
request that will be performed against the API.
fn delete(path: &'static str) -> HttpRequest<Self> where Self: 'static
Returns a DELETE
request that will be performed against the API.
fn head(path: &'static str) -> HttpRequest<Self> where Self: 'static
Returns a HEAD
request that will be performed against the API.
fn trace(path: &'static str) -> HttpRequest<Self> where Self: 'static
Returns a TRACE
request that will be performed against the API.
fn connect(path: &'static str) -> HttpRequest<Self> where Self: 'static
Returns a CONNECT
request that will be performed against the API.
fn patch(path: &'static str) -> HttpRequest<Self> where Self: 'static
Returns a PATCH
request that will be performed against the API.
fn ext(http_verb: &'static str, path: &'static str) -> HttpRequest<Self> where Self: 'static
Returns a request for the specified HTTP verb extension that will be performed against the API.