Struct lta::ureq_blocking::Agent

pub struct Agent { /* private fields */ }
Expand description

Agents keep state between requests.

By default, no state, such as cookies, is kept between requests. But by creating an agent as entry point for the request, we can keep a state.

let mut agent = ureq::agent();

agent
    .post("http://example.com/post/login")
    .call()?;

let secret = agent
    .get("http://example.com/get/my-protected-page")
    .call()?
    .into_string()?;

  println!("Secret is: {}", secret);

Agent uses an inner Arc, so cloning an Agent results in an instance that shares the same underlying connection pool and other state.

Implementations§

§

impl Agent

pub fn new() -> Agent

Creates an Agent with default settings.

Same as AgentBuilder::new().build().

pub fn request(&self, method: &str, path: &str) -> Request

Make a request with the HTTP verb as a parameter.

This allows making requests with verbs that don’t have a dedicated method.

If you’ve got an already-parsed Url, try request_url.

use ureq::Response;
let agent = ureq::agent();

let resp: Response = agent
    .request("OPTIONS", "http://example.com/")
    .call()?;

pub fn request_url(&self, method: &str, url: &Url) -> Request

Make a request using an already-parsed Url.

This is useful if you’ve got a parsed Url from some other source, or if you want to parse the URL and then modify it before making the request. If you’d just like to pass a String or a &str, try request.

use {url::Url, ureq::Response};
let agent = ureq::agent();

let mut url: Url = "http://example.com/some-page".parse()?;
url.set_path("/get/robots.txt");
let resp: Response = agent
    .request_url("GET", &url)
    .call()?;

pub fn get(&self, path: &str) -> Request

Make a GET request from this agent.

pub fn head(&self, path: &str) -> Request

Make a HEAD request from this agent.

pub fn patch(&self, path: &str) -> Request

Make a PATCH request from this agent.

pub fn post(&self, path: &str) -> Request

Make a POST request from this agent.

pub fn put(&self, path: &str) -> Request

Make a PUT request from this agent.

pub fn delete(&self, path: &str) -> Request

Make a DELETE request from this agent.

Trait Implementations§

§

impl Clone for Agent

§

fn clone(&self) -> Agent

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for Agent

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Agent

§

impl Send for Agent

§

impl Sync for Agent

§

impl Unpin for Agent

§

impl !UnwindSafe for Agent

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.

§

impl<T> Instrument for T

§

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

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

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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