1
0
mirror of https://github.com/actix/actix-website synced 2025-01-23 08:34:35 +01:00

31 lines
838 B
Rust
Raw Normal View History

2018-05-24 10:13:55 -07:00
// <url>
2019-06-28 13:31:30 -04:00
use actix_web::{guard, http::header, HttpRequest, HttpResponse, Result};
2018-05-24 10:13:55 -07:00
fn index(req: HttpRequest) -> Result<HttpResponse> {
let url = req.url_for("foo", &["1", "2", "3"])?; // <- generate url for "foo" resource
2019-06-25 18:20:36 -04:00
2018-05-24 10:13:55 -07:00
Ok(HttpResponse::Found()
.header(header::LOCATION, url.as_str())
.finish())
}
2019-06-17 04:12:11 -04:00
pub fn main() {
2019-06-28 13:31:30 -04:00
use actix_web::{web, App, HttpServer};
2019-06-25 18:20:36 -04:00
HttpServer::new(|| {
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))
})
.bind("127.0.0.1:8088")
.unwrap()
.run()
.unwrap();
2018-05-24 10:13:55 -07:00
}
// </url>