pub trait RequestModifiers: RequestInfo {
    // Provided methods
    fn authorization_header(
        request_builder: RequestBuilder,
        token: &str
    ) -> RequestBuilder { ... }
    fn create_endpoint(endpoint: &str) -> String { ... }
}
Expand description

This trait provides methods for modifying the struct in a specific way:

Provided Methods§

source

fn authorization_header( request_builder: RequestBuilder, token: &str ) -> RequestBuilder

Adds an Authorization header to the given RequestBuilder with the provided token.

The Authorization header follows the format “Bearer TOKEN”, where TOKEN is the authentication token used for authorization.

Arguments
  • request_builder - The RequestBuilder to add the header to.
  • token - The authentication token to include in the Authorization header.
Returns

The modified RequestBuilder with the Authorization header added.

Example
use reqwest::RequestBuilder;
let request_builder = reqwest::Client::new().get("https://example.com"); 
let token = "YOUR_AUTH_TOKEN";
let modified_request_builder = authorization_header(&request_builder, token);
source

fn create_endpoint(endpoint: &str) -> String

Joins the given endpoint with the base URL.

Arguments
  • endpoint - The endpoint to join with the base URL.
Returns

The joined URL as a String.

Example
struct MyStruct;
impl RequestHandler for ... {
    const BASE_URL: &'static str = "https://api.example.com";
}
fn main(){
   let url =  MyStruct::create_endpoint("get");
   assert_eq!(url,"https://api.example.com/get"); // using the default implementation
}

Implementors§