Skip to main content

ProxyRouterExt

Trait ProxyRouterExt 

Source
pub trait ProxyRouterExt<S> {
    // Required method
    fn proxy_route<T: TargetResolver>(self, path: &str, target: T) -> Self;
}
Expand description

Extension trait for axum::Router that adds proxy routing capabilities.

This trait provides a convenient way to add proxy routes to an Axum router with support for both static and dynamic target URLs.

Required Methods§

Source

fn proxy_route<T: TargetResolver>(self, path: &str, target: T) -> Self

Add a proxy route that forwards requests to a target URL.

The target can be:

  • A static string (&str or String)
  • A TemplateTarget for dynamic URL generation based on path parameters
  • Any custom type implementing TargetResolver
§Arguments
  • path - The route path pattern (e.g., /api/{id} or /proxy/{*rest})
  • target - The target URL or resolver
§Example
use axum::Router;
use axum_reverse_proxy::{ProxyRouterExt, proxy_template};

let app: Router = Router::new()
    // Static proxy
    .proxy_route("/api/{*rest}", "https://api.example.com")
    // Dynamic proxy with path substitution
    .proxy_route("/users/{id}", proxy_template("https://users.example.com/{id}"));

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<S> ProxyRouterExt<S> for Router<S>
where S: Clone + Send + Sync + 'static,

Source§

fn proxy_route<T: TargetResolver>(self, path: &str, target: T) -> Self

Implementors§