Crate arc_reactor[][src]

Arc-reactor



An asynchronous, multi-threaded and minimal web framework for Rust.

Crates.io

Features

  • Asynchronous. In arc reactor, route handlers are asynchronous by default.

  • Integration With futures-await. The #[service] proc macro not only derives the ArcService trait for your route handler, but also marks it as #[async] so you can await on futures in your route handlers with no extra stress.

  • Intuitive Middleware System. arc reactor exposes a middleware system that is easy to reason about.

  • Minimalistic. arc reactor is designed to be a very thin abstraction over tokio and hyper.

  • Nightly Rust. arc reactor uses a lot of cool features, including proc_macros which are only available on the nightly channel.

Installation

Add this to your cargo.toml

arc - reactor = "0.1"

Guides

Check out the examples folder to get a feel for how arc reactor, it's well documented. and i'm terrible at explaining things without using code.

Demo

#![feature(proc_macro, generators, proc_macro_non_items)] // <== need to add this.
extern crate arc_reactor;
extern crate futures_await as futures;
extern crate tokio;
#[macro_use]
extern crate serde_json;

use arc_reactor::{prelude::*, core::ArcReactor, routing::Router};

fn main() {
    let server = ArcReactor::default()
        .routes(rootRoutes())
        .port(3000)
        .start()
        .expect("couldn't start server");

    tokio::run(server)
}

fn rootRoutes() -> Router {
    Router::new().get("/", IndexRoute)
}

#[service]
fn IndexRoute(_req: Request, mut res: Response) {
    let isAuth = await!(fakeFuture()).unwrap();
    if isAuth {
        let payload = json!({
            "data": "hello world"
        });

        return Ok(payload.into()); // convert json to json response.
    }

    res.set_status(400);
    Err(res)
}

fn fakeFuture() -> impl Future<Item = bool, Error = ()> {
    futures::future::ok(true)
}

Re-exports

pub use futures::prelude::*;

Modules

contrib

Utilities that make working with arc reactor easier.

core
header

HTTP header types

prelude
proto
routing

Macros

mw

Set middlewares that should be executed on a request.

Structs

StatusCode

An HTTP status code (status-code in RFC 7230 et al.).