pub struct Request { /* private fields */ }Expand description
An HTTP request.
Generally created by the tinyget::get-style
functions, corresponding to the HTTP method we want to use.
§Example
let request = tinyget::get("http://example.com");After creating the request, you would generally call
send or
send_lazy on it, as it
doesn’t do much on its own.
Implementations§
Source§impl Request
impl Request
Sourcepub fn new<T: Into<URL>>(url: T) -> Request
pub fn new<T: Into<URL>>(url: T) -> Request
Creates a new HTTP Request.
This is only the request’s data, it is not sent yet. For
sending the request, see send.
Sourcepub fn with_header<T: Into<String>, U: Into<String>>(
self,
key: T,
value: U,
) -> Request
pub fn with_header<T: Into<String>, U: Into<String>>( self, key: T, value: U, ) -> Request
Adds a header to the request this is called on. Use this function to add headers to your requests.
Sourcepub fn with_query<T: Into<String>, U: Into<String>>(
self,
key: T,
value: U,
) -> Request
pub fn with_query<T: Into<String>, U: Into<String>>( self, key: T, value: U, ) -> Request
Adds a query parameter to the URL.
Sourcepub fn with_timeout(self, timeout: u64) -> Request
pub fn with_timeout(self, timeout: u64) -> Request
Sets the request timeout in seconds.
Sourcepub fn with_max_redirects(self, max_redirects: usize) -> Request
pub fn with_max_redirects(self, max_redirects: usize) -> Request
Sets the max redirects we follow until giving up. 100 by default.
Warning: setting this to a very high number, such as 1000, may cause a stack overflow if that many redirects are followed. If you have a use for so many redirects that the stack overflow becomes a problem, please open an issue.
Sourcepub fn send(self) -> Result<Response, Error>
pub fn send(self) -> Result<Response, Error>
Sends this request to the host.
§Errors
Returns Err if we run into an error while sending the
request, or receiving/parsing the response. The specific error
is described in the Err, and it can be any
tinyget::Error except
InvalidUtf8InBody.