← Back to list

Warp | 14, Redirect

We can use a redirect to navigate to another route.

Mike Code · 2026-06-16 14:35 · 0 claps · 0.5 min read
#rust #warp
Open on Medium ↗

Warp | 14, Redirect

We can use a redirect to navigate to another route.

(***Youtube Video***)

use warp::Filter;

#[tokio::main]
async fn main() {
    let app = app();

    warp::serve(app)
        .run(([0,0,0,0], 3000))
        .await;
}

fn app() -> impl Filter<Extract = impl warp::Reply, Error = warp::Rejection> + Clone {
    let root = warp::path!().map(|| "Home!");


    let hello = warp::get().and(warp::path!("hello")).and_then(hello_handler);
    let world = warp::get().and(warp::path!("world")).and_then(world_handler);

    root
        .or(hello)
        .or(world)

}

async fn hello_handler () -> Result<impl warp::Reply , warp::Rejection> {
    Ok(warp::redirect(warp::http::Uri::from_static("/world")))
}

async fn world_handler () -> Result<warp::reply::WithStatus<String> , warp::Rejection> {
    Ok(warp::reply::with_status("world".to_string(), warp::http::StatusCode::OK))
}

We create two routes, hello and world. In the hello route handler, we call Warp’s redirect function to send the user to the world route. So when a user visits the hello route, they are automatically redirected to world.


메타데이터
post_id
ab3cc4ad2bc7
slug
warp-14-redirect-ab3cc4ad2bc7
url
https://medium.com/@mikecode/warp-14-redirect-ab3cc4ad2bc7
canonical_url
https://medium.com/@mikecode/warp-14-redirect-ab3cc4ad2bc7
author_url
https://medium.com/@mikecode
status
ok
fetched_at
2026-06-21 23:24:37