pub struct HttpRequest<C> { /* private fields */ }
Implementations§
Source§impl<C> HttpRequest<C>
impl<C> HttpRequest<C>
Sourcepub fn set_uri<T>(self, uri: T) -> Self
pub fn set_uri<T>(self, uri: T) -> Self
Sets the URI for the HTTP request.
Accepts any type that can be converted into a Uri
.
§Examples
request.set_uri("https://example.com/path");
request.set_uri(Uri::from_static("https://example.com/path"));
Sourcepub fn set_method<T>(self, method: T) -> Self
pub fn set_method<T>(self, method: T) -> Self
Sets the HTTP method for the request (GET, POST, PUT, etc.).
Accepts any type that can be converted into a Method
.
§Examples
request.set_method("POST");
request.set_method(Method::POST);
Sourcepub fn set_header<K, T>(self, key: K, value: T) -> Selfwhere
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<T>,
<HeaderValue as TryFrom<T>>::Error: Into<Error>,
pub fn set_header<K, T>(self, key: K, value: T) -> Selfwhere
HeaderName: TryFrom<K>,
<HeaderName as TryFrom<K>>::Error: Into<Error>,
HeaderValue: TryFrom<T>,
<HeaderValue as TryFrom<T>>::Error: Into<Error>,
Sets a header in the HTTP request. Note: For HTTP/2 requests, connection-specific headers will be automatically removed. The ‘host’ header is mandatory in HTTP/1.1 and will be added by default if not set.
§Examples
request.set_header("content-type", "application/json");
request.set_header(HeaderName::from_static("authorization"), "Bearer token");
Sourcepub fn set_version(self, version: Version) -> Self
pub fn set_version(self, version: Version) -> Self
Sets the HTTP version for the request. Default version is HTTP/1.1 if not specified.
§Examples
request.set_version(Version::HTTP_11);
request.set_version(Version::HTTP_2);
Source§impl HttpRequest<MonoioClient>
impl HttpRequest<MonoioClient>
Sourcepub async fn send(self) -> Result<HttpResponse<HttpBody>, Error>
pub async fn send(self) -> Result<HttpResponse<HttpBody>, Error>
Sends the HTTP request without a body. Returns a Result containing either the HTTP response or an error.
Sourcepub async fn send_body(
self,
body: impl Into<Option<Bytes>>,
) -> Result<HttpResponse<HttpBody>, Error>
pub async fn send_body( self, body: impl Into<Option<Bytes>>, ) -> Result<HttpResponse<HttpBody>, Error>
Sends the HTTP request with an optional body.
The body can be provided as any type that can be converted into Option<Bytes>
.
Returns a Result containing either the HTTP response or an error.
§Examples
let response = request.send_body(Some(Bytes::from("request body"))).await?;
let response = request.send_body(None).await?; // No body