pub struct Client<'a> { /* private fields */ }Expand description
Builder for constructing and sending a blocking HTTP request.
Defaults to GET when created via Default.
Implementations§
Source§impl<'a> Client<'a>
impl<'a> Client<'a>
Sourcepub fn with_user_agent(agent: impl Into<Cow<'a, str>>) -> Self
pub fn with_user_agent(agent: impl Into<Cow<'a, str>>) -> Self
Creates a new builder with a default User-Agent header.
The User-Agent is only applied if the request does not already set one.
Sourcepub fn headers<I>(self, headers: I) -> Selfwhere
I: IntoIterator<Item = Header<'a>>,
pub fn headers<I>(self, headers: I) -> Selfwhere
I: IntoIterator<Item = Header<'a>>,
Adds multiple headers.
§Examples
let resp = curl_rest::Client::default()
.get()
.headers([
curl_rest::Header::Accept("application/json".into()),
curl_rest::Header::UserAgent("curl-rest/0.1".into()),
])
.send("https://example.com/users")?;§Errors
This method does not return errors. Header validation happens in send.
Sourcepub fn query_param(self, param: QueryParam<'a>) -> Self
pub fn query_param(self, param: QueryParam<'a>) -> Self
Sourcepub fn query_param_kv(
self,
key: impl Into<Cow<'a, str>>,
value: impl Into<Cow<'a, str>>,
) -> Self
pub fn query_param_kv( self, key: impl Into<Cow<'a, str>>, value: impl Into<Cow<'a, str>>, ) -> Self
Sourcepub fn query_params<I>(self, params: I) -> Selfwhere
I: IntoIterator<Item = QueryParam<'a>>,
pub fn query_params<I>(self, params: I) -> Selfwhere
I: IntoIterator<Item = QueryParam<'a>>,
Adds multiple query parameters.
§Examples
let resp = curl_rest::Client::default()
.get()
.query_params([
curl_rest::QueryParam::new("sort", "desc"),
curl_rest::QueryParam::new("limit", "50"),
])
.send("https://example.com/items")?;§Errors
This method does not return errors. URL validation happens in send.
Sourcepub fn body_bytes(self, bytes: impl Into<Cow<'a, [u8]>>) -> Self
pub fn body_bytes(self, bytes: impl Into<Cow<'a, [u8]>>) -> Self
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Client<'a>
impl<'a> RefUnwindSafe for Client<'a>
impl<'a> Send for Client<'a>
impl<'a> Sync for Client<'a>
impl<'a> Unpin for Client<'a>
impl<'a> UnwindSafe for Client<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more