mirror of
https://github.com/actix/actix-website
synced 2024-11-30 19:14:36 +01:00
27 lines
572 B
Rust
27 lines
572 B
Rust
// <json-resp>
|
|
use actix_web::{get, web, HttpResponse, Result};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
struct MyObj {
|
|
name: String,
|
|
}
|
|
|
|
#[get("/a/{name}")]
|
|
async fn index(obj: web::Path<MyObj>) -> Result<HttpResponse> {
|
|
Ok(HttpResponse::Ok().json(MyObj {
|
|
name: obj.name.to_string(),
|
|
}))
|
|
}
|
|
|
|
#[actix_web::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
use actix_web::{App, HttpServer};
|
|
|
|
HttpServer::new(|| App::new().service(index))
|
|
.bind("127.0.0.1:8080")?
|
|
.run()
|
|
.await
|
|
}
|
|
// </json-resp>
|