2019-06-17 21:15:33 +02:00
|
|
|
// <json-resp>
|
2019-06-26 07:58:47 +02:00
|
|
|
use actix_web::{web, HttpResponse, Result};
|
|
|
|
use serde::{Deserialize, Serialize};
|
2019-06-17 21:15:33 +02:00
|
|
|
|
2019-06-26 07:58:47 +02:00
|
|
|
#[derive(Serialize, Deserialize)]
|
2019-06-17 21:15:33 +02:00
|
|
|
struct MyObj {
|
|
|
|
name: String,
|
|
|
|
}
|
|
|
|
|
2019-06-26 07:58:47 +02:00
|
|
|
fn index(obj: web::Path<MyObj>) -> Result<HttpResponse> {
|
|
|
|
Ok(HttpResponse::Ok().json(MyObj {
|
|
|
|
name: obj.name.to_string(),
|
2019-06-17 21:15:33 +02:00
|
|
|
}))
|
|
|
|
}
|
|
|
|
|
2019-06-19 06:20:50 +02:00
|
|
|
pub fn main() {
|
2019-06-26 07:58:47 +02:00
|
|
|
use actix_web::{App, HttpServer};
|
|
|
|
|
|
|
|
HttpServer::new(|| App::new().route(r"/a/{name}", web::get().to(index)))
|
|
|
|
.bind("127.0.0.1:8088")
|
|
|
|
.unwrap()
|
|
|
|
.run()
|
|
|
|
.unwrap();
|
2019-06-17 21:15:33 +02:00
|
|
|
}
|
|
|
|
// </json-resp>
|