Skip to main content

Http

Struct Http 

Source
pub struct Http;
Expand description

The outbound HTTP client.

A facade over whichever Transport is installed, so fake swaps what every call in the process does — the same way rebinding a service swaps what a Rainier facade sees.

Implementations§

Source§

impl Http

Source

pub fn get(url: impl Into<String>) -> PendingRequest

GET url.

Source

pub fn post(url: impl Into<String>) -> PendingRequest

POST url.

Source

pub fn put(url: impl Into<String>) -> PendingRequest

PUT url.

Source

pub fn patch(url: impl Into<String>) -> PendingRequest

PATCH url.

Source

pub fn delete(url: impl Into<String>) -> PendingRequest

DELETE url.

Source

pub fn request( method: impl Into<String>, url: impl Into<String>, ) -> PendingRequest

A request with any method.

Source

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.

Source

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.

Source

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.

Source

pub fn faking() -> Arc<FakeTransport> ⓘ

The installed fake.

§Panics

If nothing is faking. Every Rainier double refuses to let an assertion pass vacuously, and this is the same rule: an assert_sent that silently passed because somebody forgot fake is the most dangerous test in a suite.

Source

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.

Source

pub fn assert_not_sent(matches: impl Fn(&RecordedRequest) -> bool)

Panic if a matching request was sent.

§Panics

If one was, or if nothing is faking.

Source

pub fn assert_nothing_sent()

Panic unless nothing was sent.

§Panics

If anything was, or if nothing is faking.

Source

pub fn clear()

Stop faking, and install nothing in its place.

Clears both the thread scope and the process-wide binding.

Auto Trait Implementations§

§

impl Freeze for Http

§

impl RefUnwindSafe for Http

§

impl Send for Http

§

impl Sync for Http

§

impl Unpin for Http

§

impl UnsafeUnpin for Http

§

impl UnwindSafe for Http

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more