mirror of
https://github.com/actix/actix-website
synced 2024-12-04 04:31:55 +01:00
24 lines
689 B
Rust
24 lines
689 B
Rust
// <url>
|
|
use actix_web::{
|
|
guard, http::header, http::Method, web, App, HttpRequest, HttpResponse, Result,
|
|
};
|
|
|
|
fn index(req: HttpRequest) -> Result<HttpResponse> {
|
|
let url = req.url_for("foo", &["1", "2", "3"])?; // <- generate url for "foo" resource
|
|
Ok(HttpResponse::Found()
|
|
.header(header::LOCATION, url.as_str())
|
|
.finish())
|
|
}
|
|
|
|
fn main() {
|
|
App::new()
|
|
.service(
|
|
web::resource("/test/{a}/{b}/{c}")
|
|
.name("foo") // <- set resource name, then it could be used in `url_for`
|
|
.guard(guard::Get())
|
|
.to(|| HttpResponse::Ok()),
|
|
)
|
|
.route("/test/", web::get().to(index));
|
|
}
|
|
// </url>
|