pub struct Http;Expand description
Implementations§
Source§impl Http
impl Http
Sourcepub fn get(url: impl Into<String>) -> PendingRequest
pub fn get(url: impl Into<String>) -> PendingRequest
GET url.
Sourcepub fn post(url: impl Into<String>) -> PendingRequest
pub fn post(url: impl Into<String>) -> PendingRequest
POST url.
Sourcepub fn put(url: impl Into<String>) -> PendingRequest
pub fn put(url: impl Into<String>) -> PendingRequest
PUT url.
Sourcepub fn patch(url: impl Into<String>) -> PendingRequest
pub fn patch(url: impl Into<String>) -> PendingRequest
PATCH url.
Sourcepub fn delete(url: impl Into<String>) -> PendingRequest
pub fn delete(url: impl Into<String>) -> PendingRequest
DELETE url.
Sourcepub fn request(
method: impl Into<String>,
url: impl Into<String>,
) -> PendingRequest
pub fn request( method: impl Into<String>, url: impl Into<String>, ) -> PendingRequest
A request with any method.
Sourcepub fn install(transport: Arc<dyn Transport>)
pub fn install(transport: Arc<dyn Transport>)
Install the transport every call uses.
Called once at boot. Calling it again replaces the binding, which is
what fake does.
Sourcepub fn fake() -> Arc<FakeTransport> ⓘ
pub fn fake() -> Arc<FakeTransport> ⓘ
Record every outbound call instead of making it.
Returns the fake, so a test can queue answers:
Http::fake().responding(200, r#"{"ok":true}"#);Nothing reaches the network afterwards, which is the other half of the point: a suite that accidentally calls a real endpoint is a suite that fails when somebody runs it on a train.
Sourcepub fn fake_globally() -> Arc<FakeTransport> ⓘ
pub fn fake_globally() -> Arc<FakeTransport> ⓘ
Record every outbound call in the whole process.
For code that spawns: a task started by the code under test inherits no
thread scope, so fake would not catch its calls.
The trade is that two tests doing this at once overwrite each other, so a suite using it has to run those tests one at a time.
Sourcepub fn faking() -> Arc<FakeTransport> ⓘ
pub fn faking() -> Arc<FakeTransport> ⓘ
Sourcepub fn assert_sent(matches: impl Fn(&RecordedRequest) -> bool)
pub fn assert_sent(matches: impl Fn(&RecordedRequest) -> bool)
Panic unless a matching request was sent. See
FakeTransport::assert_sent.
§Panics
If none matched, or if nothing is faking.