pub struct Request { /* private fields */ }Expand description
Represents an HTTP request.
§Fields
method: The HTTP method of the request (e.g., GET, POST).host: The host of the request (e.g., example.com).path: The path of the request (e.g., /api/v1/resource).query: The query string of the request (e.g., ?key=value).headers: A collection of HTTP headers as key-value pairs.body: The binary body of the request.
Implementations§
Source§impl Request
impl Request
Sourcepub fn set_header<K, V>(&mut self, key: K, value: V) -> &mut Request
pub fn set_header<K, V>(&mut self, key: K, value: V) -> &mut Request
Adds a header to the request.
This function inserts a key-value pair into the request headers.
The key and value are converted into String, allowing for efficient handling of both owned and borrowed string data.
§Parameters
key: The header key, which will be converted into aString.value: The value of the header, which will be converted into aString.
§Returns
- Returns a mutable reference to the current instance (
&mut Self), allowing for method chaining.
Sourcepub fn set_body<T>(&mut self, body: T) -> &mut Request
pub fn set_body<T>(&mut self, body: T) -> &mut Request
Set the body of the response.
This method allows you to set the body of the response by converting the provided
value into a RequestBody type. The body is updated with the converted value,
and the method returns a mutable reference to the current instance for method chaining.
§Parameters
body: The body of the response to be set. It can be any type that can be converted into aRequestBodyusing theIntotrait.
§Return Value
- Returns a mutable reference to the current instance of the struct, enabling method chaining. Set the body of the response.
This method allows you to set the body of the response by converting the provided
value into a RequestBody type. The body is updated with the converted value,
and the method returns a mutable reference to the current instance for method chaining.
§Parameters
body: The body of the response to be set. It can be any type that can be converted into aRequestBodyusing theIntotrait.
§Return Value
- Returns a mutable reference to the current instance of the struct, enabling method chaining.
Sourcepub fn set_method<T>(&mut self, method: T) -> &mut Request
pub fn set_method<T>(&mut self, method: T) -> &mut Request
Set the HTTP method of the request.
This method allows you to set the HTTP method (e.g., GET, POST) of the request
by converting the provided value into a RequestMethod type. The method is updated
with the converted value, and the method returns a mutable reference to the current
instance for method chaining.
§Parameters
method: The HTTP method to be set for the request. It can be any type that can be converted into aRequestMethodusing theIntotrait.
§Return Value
- Returns a mutable reference to the current instance of the struct, enabling method chaining.
Sourcepub fn set_host<T>(&mut self, host: T) -> &mut Request
pub fn set_host<T>(&mut self, host: T) -> &mut Request
Set the host of the request.
This method allows you to set the host (e.g., www.example.com) for the request
by converting the provided value into a RequestHost type. The host is updated
with the converted value, and the method returns a mutable reference to the current
instance for method chaining.
§Parameters
host: The host to be set for the request. It can be any type that can be converted into aRequestHostusing theIntotrait.
§Return Value
- Returns a mutable reference to the current instance of the struct, enabling method chaining.
Sourcepub fn set_path<T>(&mut self, path: T) -> &mut Request
pub fn set_path<T>(&mut self, path: T) -> &mut Request
Set the path of the request.
This method allows you to set the path (e.g., /api/v1/resource) for the request
by converting the provided value into a RequestPath type. The path is updated
with the converted value, and the method returns a mutable reference to the current
instance for method chaining.
§Parameters
path: The path to be set for the request. It can be any type that can be converted into aRequestPathusing theIntotrait.
§Return Value
- Returns a mutable reference to the current instance of the struct, enabling method chaining.
Sourcepub fn set_query<T>(&mut self, query: T) -> &mut Request
pub fn set_query<T>(&mut self, query: T) -> &mut Request
Set the query string of the request.
This method allows you to set the query string (e.g., ?key=value) for the request
by converting the provided value into a RequestQuery type. The query is updated
with the converted value, and the method returns a mutable reference to the current
instance for method chaining.
§Parameters
query: The query string to be set for the request. It can be any type that can be converted into aRequestQueryusing theIntotrait.
§Return Value
- Returns a mutable reference to the current instance of the struct, enabling method chaining.