[−][src]Struct attohttpc::RequestBuilder
Request
is the main way of performing requests.
You can create a RequestBuilder
the hard way using the new
or try_new
method,
or use one of the simpler constructors available in the crate root, such as get
post
, etc.
Methods
impl RequestBuilder
[src]
pub fn new<U>(method: Method, base_url: U) -> Self where
U: AsRef<str>,
[src]
U: AsRef<str>,
Create a new Request
with the base URL and the given method.
Panics
Panics if the base url is invalid or if the method is CONNECT.
pub fn try_new<U>(method: Method, base_url: U) -> Result<Self> where
U: AsRef<str>,
[src]
U: AsRef<str>,
Try to create a new RequestBuilder
.
If the base URL is invalid, an error is returned. If the method is CONNECT, an error is also returned. CONNECT is not yet supported.
impl<B> RequestBuilder<B>
[src]
pub fn param<V>(self, key: &str, value: V) -> Self where
V: Display,
[src]
V: Display,
Associate a query string parameter to the given value.
The same key can be used multiple times.
pub fn params<'k, 'v, P, V>(self, pairs: P) -> Self where
P: AsRef<[(&'k str, V)]>,
V: Display + 'v,
[src]
P: AsRef<[(&'k str, V)]>,
V: Display + 'v,
Associated a list of pairs to query parameters.
The same key can be used multiple times.
pub fn header<H, V>(self, header: H, value: V) -> Self where
H: IntoHeaderName,
V: HttpTryInto<HeaderValue>,
[src]
H: IntoHeaderName,
V: HttpTryInto<HeaderValue>,
Modify a header for this Request
.
If the header is already present, the value will be replaced. If you wish to append a new header,
use header_append
.
Panics
This method will panic if the value is invalid.
pub fn header_append<H, V>(self, header: H, value: V) -> Self where
H: IntoHeaderName,
V: HttpTryInto<HeaderValue>,
[src]
H: IntoHeaderName,
V: HttpTryInto<HeaderValue>,
Modify a header for this Request
.
If the header is already present, the value will be replaced. If you wish to append a new header,
use header_append
.
Panics
This method will panic if the value is invalid.
pub fn try_header<H, V>(self, header: H, value: V) -> Result<Self> where
H: IntoHeaderName,
V: HttpTryInto<HeaderValue>,
[src]
H: IntoHeaderName,
V: HttpTryInto<HeaderValue>,
Modify a header for this Request
.
If the header is already present, the value will be replaced. If you wish to append a new header,
use header_append
.
pub fn try_header_append<H, V>(self, header: H, value: V) -> Result<Self> where
H: IntoHeaderName,
V: HttpTryInto<HeaderValue>,
[src]
H: IntoHeaderName,
V: HttpTryInto<HeaderValue>,
Append a new header to this Request
.
The new header is always appended to the Request
, even if the header already exists.
pub fn bearer_auth(self, token: impl Into<String>) -> Self
[src]
Enable HTTP bearer authentication.
pub fn text(self, body: impl AsRef<str>) -> RequestBuilder<impl AsRef<[u8]>>
[src]
Set the body of this request to be text.
If the Content-Type
header is unset, it will be set to text/plain
and the carset to UTF-8.
pub fn bytes(self, body: impl AsRef<[u8]>) -> RequestBuilder<impl AsRef<[u8]>>
[src]
Set the body of this request to be bytes.
If the Content-Type
header is unset, it will be set to application/octet-stream
.
pub fn json<T: Serialize>(
self,
value: &T
) -> Result<RequestBuilder<impl AsRef<[u8]>>>
[src]
self,
value: &T
) -> Result<RequestBuilder<impl AsRef<[u8]>>>
Set the body of this request to be the JSON representation of the given object.
If the Content-Type
header is unset, it will be set to application/json
and the charset to UTF-8.
pub fn form<T: Serialize>(
self,
value: &T
) -> Result<RequestBuilder<impl AsRef<[u8]>>>
[src]
self,
value: &T
) -> Result<RequestBuilder<impl AsRef<[u8]>>>
Set the body of this request to be the URL-encoded representation of the given object.
If the Content-Type
header is unset, it will be set to application/x-www-form-urlencoded
.
pub fn max_redirections(self, max_redirections: u32) -> Self
[src]
Set the maximum number of redirections this Request
can perform.
pub fn follow_redirects(self, follow_redirects: bool) -> Self
[src]
Sets if this Request
should follow redirects, 3xx codes.
This value defaults to true.
pub fn default_charset(self, default_charset: Option<Charset>) -> Self
[src]
Set the default charset to use while parsing the response of this Request
.
If the response does not say which charset it uses, this charset will be used to decode the request.
This value defaults to None
, in which case ISO-8859-1 is used.
pub fn allow_compression(self, allow_compression: bool) -> Self
[src]
Sets if this Request
will announce that it accepts compression.
This value defaults to true. Note that this only lets the browser know that this Request
supports
compression, the server might choose not to compress the content.
impl<B: AsRef<[u8]>> RequestBuilder<B>
[src]
pub fn prepare(self) -> PreparedRequest<B>
[src]
Create a PreparedRequest
from this RequestBuilder
.
Panics
Will panic if an error occurs trying to prepare the request. It shouldn't happen.
pub fn try_prepare(self) -> Result<PreparedRequest<B>>
[src]
Create a PreparedRequest
from this RequestBuilder
.
pub fn send(self) -> Result<Response>
[src]
Send this request directly.
Trait Implementations
Auto Trait Implementations
impl<B> Send for RequestBuilder<B> where
B: Send,
B: Send,
impl<B> Sync for RequestBuilder<B> where
B: Sync,
B: Sync,
impl<B> Unpin for RequestBuilder<B> where
B: Unpin,
B: Unpin,
impl<B> UnwindSafe for RequestBuilder<B> where
B: UnwindSafe,
B: UnwindSafe,
impl<B> RefUnwindSafe for RequestBuilder<B> where
B: RefUnwindSafe,
B: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,