Crates.io | actix-json-responder |
lib.rs | actix-json-responder |
version | 0.2.1 |
source | src |
created_at | 2021-06-23 12:48:06.774504 |
updated_at | 2022-12-28 07:31:08.324965 |
description | A procedural macro to reduce json response boilerplate on actix projects. |
homepage | |
repository | https://github.com/eisberg-labs/actix-json-responder |
max_upload_size | |
id | 413911 |
size | 16,981 |
A procedural macro to reduce json response boilerplate on actix projects.
Implementing struct has to be serializable. Example shown in tests and below:
#[macro_use]
extern crate actix_json_responder;
use serde::Serialize;
use actix_web::{web, App, HttpServer};
#[derive(Serialize, JsonResponder, PartialEq)]
struct HelloStruct {
title: String,
}
async fn index() -> Result<HelloStruct, Error> {
Ok(HelloStruct { title: "Hello json!".to_string() })
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new()
.service(web::resource("/index.html").to(index)))
.bind("127.0.0.1:8888")?
.run()
.await
}
Working example is in example directory.
Distributed under the terms of MIT license and Apache license.