pub struct HttpSession { /* private fields */ }Expand description
An HTTP session for communicating with a single server.
This struct manages cookies, authentication, and provides methods for making HTTP requests to a specific server. All requests made through this session will automatically include appropriate cookies and authentication tokens.
Implementations§
Source§impl HttpSession
impl HttpSession
Sourcepub async fn get(&mut self, rel: &str) -> Result<Response<Incoming>, Error>
pub async fn get(&mut self, rel: &str) -> Result<Response<Incoming>, Error>
Makes a GET request to the specified relative path.
This method automatically includes session cookies and handles authentication.
§Arguments
rel- Relative path to request (e.g., “api/status”)
§Returns
The HTTP response from the server, or an error if the request fails.
§Examples
let response = session.get("api/status").await?;
println!("Status: {}", response.status());Sourcepub async fn req_accepts(
&mut self,
rel: &str,
accepts: &[HeaderValue],
method: Method,
body: Body,
) -> Result<Response<Incoming>, Error>
pub async fn req_accepts( &mut self, rel: &str, accepts: &[HeaderValue], method: Method, body: Body, ) -> Result<Response<Incoming>, Error>
Makes an HTTP request with custom Accept headers and method.
This method provides more control over the HTTP request, allowing you to specify Accept headers and HTTP method.
§Arguments
rel- Relative path to requestaccepts- Array of Accept header values to includemethod- HTTP method to use (GET, POST, PUT, etc.)body- Request body
§Returns
The HTTP response from the server, or an error if the request fails.
Sourcepub async fn post(
&mut self,
rel: &str,
body: MyBody,
) -> Result<Response<Incoming>, Error>
pub async fn post( &mut self, rel: &str, body: MyBody, ) -> Result<Response<Incoming>, Error>
Makes a POST request to the specified relative path.
This method automatically includes session cookies and sets the Content-Type header to “application/json”.
§Arguments
rel- Relative path to post to (e.g., “api/submit”)body- Request body containing the data to post
§Returns
The HTTP response from the server, or an error if the request fails.
§Examples
let body = axum::body::Body::from(r#"{"key": "value"}"#);
let response = session.post("api/data", body).await?;Trait Implementations§
Source§impl Clone for HttpSession
impl Clone for HttpSession
Source§fn clone(&self) -> HttpSession
fn clone(&self) -> HttpSession
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more