1
0
mirror of https://github.com/actix/actix-website synced 2024-12-04 20:51:54 +01:00
actix-website/examples/url-dispatch/src/urls.rs

24 lines
693 B
Rust
Raw Normal View History

2018-05-24 19:13:55 +02:00
// <url>
2019-06-17 08:08:42 +02:00
use actix_web::{
guard, http::header, http::Method, web, App, HttpRequest, HttpResponse, Result,
};
2018-05-24 19:13:55 +02:00
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())
}
2019-06-17 10:12:11 +02:00
pub fn main() {
2019-06-17 08:08:42 +02:00
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));
2018-05-24 19:13:55 +02:00
}
// </url>