1
0
mirror of https://github.com/actix/actix-website synced 2025-03-16 05:02:45 +01:00

28 lines
546 B
Rust
Raw Normal View History

2019-06-17 15:15:33 -04:00
// <json-resp>
use actix_web::{get, web, Responder, Result};
use serde::Serialize;
2019-06-17 15:15:33 -04:00
#[derive(Serialize)]
2019-06-17 15:15:33 -04:00
struct MyObj {
name: String,
}
2020-09-12 16:21:54 +01:00
#[get("/a/{name}")]
async fn index(name: web::Path<String>) -> Result<impl Responder> {
let obj = MyObj {
name: name.to_string(),
};
Ok(web::Json(obj))
2019-06-17 15:15:33 -04:00
}
2020-09-12 16:21:54 +01:00
#[actix_web::main]
2019-12-29 02:59:48 +09:00
async fn main() -> std::io::Result<()> {
2019-06-26 01:58:47 -04:00
use actix_web::{App, HttpServer};
2020-09-12 16:21:54 +01:00
HttpServer::new(|| App::new().service(index))
.bind("127.0.0.1:8080")?
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>