pub struct HttpRequestBuilder {Show 13 fields
pub method: String,
pub url: String,
pub params: Option<HashMap<String, String>>,
pub headers: Option<HashMap<String, String>>,
pub body: Option<Value>,
pub follow_redirects: Option<bool>,
pub max_redirections: Option<u32>,
pub connect_timeout: Option<u64>,
pub read_timeout: Option<u64>,
pub timeout: Option<u64>,
pub allow_compression: Option<bool>,
pub body_type: Option<BodyType>,
pub response_type: Option<ResponseType>,
}
Expand description
The builder for HttpRequestOptions.
§Examples
let mut builder = HttpRequestBuilder::new("GET", "http://example.com");
let option = builder.response_type(ResponseType::Text)
.follow_redirects(false)
.build();
if let Ok(response) = make_request(option) {
println!("Response: {}", response);
} else {
println!("Something Happened!");
}
Fields§
§method: String
The request method (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, CONNECT or TRACE)
url: String
The request URL
params: Option<HashMap<String, String>>
The request query params
headers: Option<HashMap<String, String>>
The request headers
body: Option<Value>
The request body
follow_redirects: Option<bool>
Whether to follow redirects or not
max_redirections: Option<u32>
Max number of redirections to follow
connect_timeout: Option<u64>
Connect timeout for the request
read_timeout: Option<u64>
Read timeout for the request
timeout: Option<u64>
Timeout for the whole request
allow_compression: Option<bool>
Whether the request will announce that it accepts compression
body_type: Option<BodyType>
The body type (defaults to Auto)
response_type: Option<ResponseType>
The response type (defaults to Json)
Implementations§
Source§impl HttpRequestBuilder
impl HttpRequestBuilder
Sourcepub fn new(method: impl Into<String>, url: impl Into<String>) -> Self
pub fn new(method: impl Into<String>, url: impl Into<String>) -> Self
Initializes a new instance of the HttpRequestBuilder.
Sourcepub fn follow_redirects(self, follow_redirects: bool) -> Self
pub fn follow_redirects(self, follow_redirects: bool) -> Self
Sets whether the request should follow redirects or not.
Sourcepub fn max_redirections(self, max_redirections: u32) -> Self
pub fn max_redirections(self, max_redirections: u32) -> Self
Sets the maximum number of redirections.
Sourcepub fn connect_timeout(self, connect_timeout: u64) -> Self
pub fn connect_timeout(self, connect_timeout: u64) -> Self
Sets the connection timeout.
Sourcepub fn read_timeout(self, read_timeout: u64) -> Self
pub fn read_timeout(self, read_timeout: u64) -> Self
Sets the read timeout.
Sourcepub fn allow_compression(self, allow_compression: bool) -> Self
pub fn allow_compression(self, allow_compression: bool) -> Self
Sets whether the request allows compressed responses or not.
Sourcepub fn response_type(self, response_type: ResponseType) -> Self
pub fn response_type(self, response_type: ResponseType) -> Self
Sets the type of the response. Interferes with the way we read the response.
Sourcepub fn build(self) -> HttpRequestOptions
pub fn build(self) -> HttpRequestOptions
Builds the HttpRequestOptions.
Auto Trait Implementations§
impl Freeze for HttpRequestBuilder
impl RefUnwindSafe for HttpRequestBuilder
impl Send for HttpRequestBuilder
impl Sync for HttpRequestBuilder
impl Unpin for HttpRequestBuilder
impl UnwindSafe for HttpRequestBuilder
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more