You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
794 B

4 years ago
  1. #[derive(Debug, Serialize, Deserialize)]
  2. struct MyObj {
  3. name: String,
  4. // number: i32,
  5. }
  6. #[get("/{id}/{name}")]
  7. async fn index(info: web::Path<(u32, String)>) -> Result<HttpResponse, Error> {
  8. let (id, name) = (info.0, info.1.clone());
  9. let template = models::CardTemplate {
  10. title: "My Title",
  11. body: name,
  12. num: id,
  13. };
  14. template
  15. .call()
  16. .map(|body| HttpResponse::Ok().content_type("text/html").body(body))
  17. .map_err(|_| {
  18. error::ErrorInternalServerError("Error while parsing template")
  19. })
  20. }
  21. /// This handler uses json extractor
  22. #[post("/extractor")]
  23. async fn extract_my_obj(item: web::Json<MyObj>) -> HttpResponse {
  24. debug!("model: {:?}", item);
  25. HttpResponse::Ok().json(item.0) // <- send response
  26. }