2018-05-24 19:13:55 +02:00
|
|
|
// <ext>
|
2019-06-28 19:31:30 +02:00
|
|
|
use actix_web::{HttpRequest, Responder};
|
2018-05-24 19:13:55 +02:00
|
|
|
|
2019-12-28 20:10:02 +01:00
|
|
|
async fn index(req: HttpRequest) -> impl Responder {
|
2019-06-17 10:12:11 +02:00
|
|
|
let url = req.url_for("youtube", &["oHg5SJYRHA0"]).unwrap();
|
2018-05-24 19:13:55 +02:00
|
|
|
assert_eq!(url.as_str(), "https://youtube.com/watch/oHg5SJYRHA0");
|
2019-06-17 10:12:11 +02:00
|
|
|
|
|
|
|
url.into_string()
|
2018-05-24 19:13:55 +02:00
|
|
|
}
|
|
|
|
|
2019-12-28 20:10:02 +01:00
|
|
|
#[actix_rt::main]
|
|
|
|
async fn main() -> std::io::Result<()> {
|
2019-06-28 19:31:30 +02:00
|
|
|
use actix_web::{web, App, HttpServer};
|
2019-06-26 00:20:36 +02:00
|
|
|
|
|
|
|
HttpServer::new(|| {
|
|
|
|
App::new()
|
|
|
|
.route("/", web::get().to(index))
|
|
|
|
.external_resource("youtube", "https://youtube.com/watch/{video_id}")
|
|
|
|
.route("/", actix_web::web::get().to(index))
|
|
|
|
})
|
2019-12-28 20:10:02 +01:00
|
|
|
.bind("127.0.0.1:8088")?
|
2019-06-26 00:20:36 +02:00
|
|
|
.run()
|
2019-12-28 20:10:02 +01:00
|
|
|
.await
|
2018-05-24 19:13:55 +02:00
|
|
|
}
|
|
|
|
// </ext>
|