Giter Site home page Giter Site logo

arc-reactor's Introduction

Arc-reactor

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"

Demo

#![feature(conservative_impl_trait, proc_macro, generators, box_syntax)] // <== need to add this.
extern crate arc_reactor;
#[macro_use]
extern crate serde_json;
use arc_reactor::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<Item=bool, Error=()> {
  futures::future::ok(true)
}

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.

Contributions

If you feel something is missing, feel free to submit a PR.

License

Refer to License.

arc-reactor's People

Contributors

seunlanlege avatar toksdotdev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.