LoginSignup
6
3

More than 3 years have passed since last update.

actix-webでリダイレクト

Last updated at Posted at 2019-08-06
main.rs
use actix_web::{
    http::{StatusCode, Method, header},
    HttpResponse, Result, Error, HttpServer,
}

fn index() -> Result<HttpResponse, Error> {
    let q = "google";
    let request_uri = format!("https://www.google.com/search?q={}", q);

    Ok(HttpResponse::TemporaryRedirect()
        .header(header::LOCATION, request_uri)
        .finish()
    )
}

fn main() -> std::io::Result<()> {
    HttpServer::new(|| App::new().service(
        web::resource("/").to(index))
    )
        .bind("127.0.0.1:8080")?
        .run()
}
6
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
3