1
0
mirror of https://github.com/actix/actix-website synced 2025-02-08 22:36:07 +01:00

26 lines
573 B
Rust
Raw Normal View History

2019-06-17 15:15:33 -04:00
// <json-resp>
2019-06-26 01:58:47 -04:00
use actix_web::{web, HttpResponse, Result};
use serde::{Deserialize, Serialize};
2019-06-17 15:15:33 -04:00
2019-06-26 01:58:47 -04:00
#[derive(Serialize, Deserialize)]
2019-06-17 15:15:33 -04:00
struct MyObj {
name: String,
}
2019-12-29 02:59:48 +09:00
async fn index(obj: web::Path<MyObj>) -> Result<HttpResponse> {
2019-06-26 01:58:47 -04:00
Ok(HttpResponse::Ok().json(MyObj {
name: obj.name.to_string(),
2019-06-17 15:15:33 -04:00
}))
}
2019-12-29 02:59:48 +09:00
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
2019-06-26 01:58:47 -04:00
use actix_web::{App, HttpServer};
HttpServer::new(|| App::new().route(r"/a/{name}", web::get().to(index)))
2019-12-29 02:59:48 +09:00
.bind("127.0.0.1:8088")?
2019-06-26 01:58:47 -04:00
.run()
2019-12-29 02:59:48 +09:00
.await
2019-06-17 15:15:33 -04:00
}
// </json-resp>