Arc-reactor

Arc Reactor

An Asynchronous, Extensible, Micro web framework for Rust.

Crates.io

Features

Installation

Add this to your cargo.toml

toml arc-reactor = "0.1"

Demo (default)

```rust extern crate arc_reactor;

[macro_use]

extern crate serdejson; use arcreactor::prelude::*; use arc_reactor::{Router, ArcReactor, StatusCode};

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

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

fn IndexRoute(_req: Request, res: Response) -> FutureResponse { let future = fakeFuture().then(|status| { match status { Ok(isAuth) => { if isAuth { let payload = json!({ "data": "hello world" }); return Ok(payload.into()) // convert json to json response. } } _ => unreachable!() } });

Box::new(future) }

fn fakeFuture() -> impl Future

Demo (unstable)

```rust

![feature(procmacro, generators, procmacrononitems)] // <== need to add this.

extern crate arc_reactor;

[macro_use]

extern crate serdejson; use arcreactor::prelude::*; use arc_reactor::{Router, ArcReactor, StatusCode};

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

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

[service]

fn IndexRoute(_req: Rrequest, res: Response) { let isAuth = await!(fakeFuture()); if isAuth { let payload = json!({ "data": "hello world" });

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

}

res.with_status(StatusCode::UnAuthorized) }

fn fakeFuture() -> impl Future

Nightly Use

Originally, arc-reactor was designed for the nightly compiler. But instabilities in libprocmacro cause it to break everytime a new nightly compiler is released.

So by default, arc-reactor no longer uses the nightly compiler, and will work out of the box with the stable compiler. 🎉 This means experimental nightly features including proc_macros are only available behind the unstable feature flag.

If you wish to use arc-reactor, with the nightly compiler and unstable feature enabled: It is recommended that you lock down the compiler version. Until libprocmacro is stablized.

If you wish to use arc-reactor with it's default features: - The trait ArcService is implemented for all functions that satisfy the signature Fn(Request, Response) -> FutureResponse - The trait MiddleWare<Request> is implemented for all functions that satisfy the signature Fn(Request) -> MiddleWareFuture<Request> - The trait MiddleWare<Response> is implemented for all functions that satisfy the signature Fn(Response) -> MiddleWareFuture<Response> - futures from futures-rs is re-exported instead of futures-await. - you lose the ability to await! on futures in your ServiceHandlers and MiddleWares. - Currently, Multipart support is implemented using unstable features, so you would have to implement your own.

Examples

Check out the examples folder and the api documentation to get a feel for how arc reactor works.
It's well documented and should get you up and running in no time.

Design

It is Strongly recommended that you read the design document, as it gives you full disclosure on arc-reactor's internals, as well as the design decisions that were made.

Contributions

Arc-Reactor is highly extensible via middlewares which are placed in the contrib module.

Some of the things are missing include: - [ ] Logger - [ ] Websocket - [ ] Support byte range headers - [x] Asynchronous StaticFileServer - [x] Json body parser - [x] Multipart Support

Feel free to submit a PR.

License

Refer to License.