Skip to content

eisberg-labs/actix-json-responder

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

A procedural macro to reduce json response boilerplate on actix projects.
https://www.amarjanica.com/lets-refactor-a-simple-procedural-macro-in-rust.

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.

About

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

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages