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, box_syntax)] // <== need to add this.
extern crate arc_reactor;
#[macro_use]
extern crate serde_json;
use arc_reactor::{prelude::*, ArcReactor, Router, StatusCode};

fn main() {
    ArcReactor::new()
        .routes(rootRoutes())
        .port(3000)
        .initiate()
        .unwrap()
    }

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(StatusCode::Unauthorized);
    Err(res)
    }

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

Re-exports

pub extern crate anymap;
pub extern crate futures;
pub extern crate hyper;
pub extern crate native_tls;
pub extern crate num_cpus;
pub extern crate percent_encoding;
pub extern crate serde_qs;
pub extern crate tokio;
pub extern crate tokio_tls;
pub extern crate lazy_static;
pub extern crate serde;
pub extern crate serde_json;
pub extern crate bytes;
pub extern crate mime;
pub extern crate mime_guess;
pub extern crate regex;
pub extern crate tokio_core;
pub use futures::prelude::*;

Modules

contrib

Utilities that make working with arc reactor easier.

core
header

Headers container, and common header fields.

prelude
proto
routing

Macros

mw

Set middlewares that should be executed on a request.

Structs

POOL

Enums

StatusCode

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