mirror of
https://github.com/actix/actix-website
synced 2024-12-02 19:52:23 +01:00
24 lines
584 B
Rust
24 lines
584 B
Rust
// <ext>
|
|
use actix_web::{get, App, HttpRequest, HttpServer, Responder};
|
|
|
|
#[get("/")]
|
|
async fn index(req: HttpRequest) -> impl Responder {
|
|
let url = req.url_for("youtube", ["oHg5SJYRHA0"]).unwrap();
|
|
assert_eq!(url.as_str(), "https://youtube.com/watch/oHg5SJYRHA0");
|
|
|
|
url.to_string()
|
|
}
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
HttpServer::new(|| {
|
|
App::new()
|
|
.service(index)
|
|
.external_resource("youtube", "https://youtube.com/watch/{video_id}")
|
|
})
|
|
.bind(("127.0.0.1", 8080))?
|
|
.run()
|
|
.await
|
|
}
|
|
// </ext>
|