#json-response #json #actix-web #proc-macro #actix

macro actix-json-responder

A procedural macro to reduce json response boilerplate on actix projects

4 releases

0.2.1 Dec 28, 2022
0.2.0 Mar 3, 2022
0.2.0-beta.1 Jan 11, 2022
0.1.0 Jun 23, 2021

#1130 in Procedural macros

22 downloads per month

MIT/Apache

7KB

Actix Json Responder Continuous Integration license-badge rust-version-badge

A procedural macro to reduce json response boilerplate on actix projects.

Usage

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.

License

Distributed under the terms of MIT license and Apache license.

Dependencies

~1.5MB
~37K SLoC