thruster

A middleware based http async web server

20 releases

0.5.0-beta8 Jul 20, 2018
0.5.0-beta5 Jul 10, 2018
0.5.0-beta3 Jun 18, 2018
0.4.5 Jun 26, 2018
0.3.4 Mar 28, 2018

#36 in #web

Download history 21/week @ 2018-05-04 26/week @ 2018-05-11 4/week @ 2018-05-18 6/week @ 2018-05-25 75/week @ 2018-06-01 25/week @ 2018-06-08 57/week @ 2018-06-15 96/week @ 2018-06-22 292/week @ 2018-06-29 75/week @ 2018-07-06 55/week @ 2018-07-13 96/week @ 2018-07-20 46/week @ 2018-07-27

286 downloads per month

Thruster

An opinionated framework for web development in rust.

Build Status

Documentation

Thruster is a web framework that aims for developers to be productive and consistent across projects and teams. Its goals are to be:

  • Opinionated
  • Fast
  • Intuitive

Thruster also

  • Does not use unsafe
  • Works in stable rust

Opinionated

thruster and thruster-cli strive to give a good way to do domain driven design. It's also designed to set you on the right path, but not obfuscate certain hard parts behind libraries. Made with science 🔭, not magic 🧙‍♂️.

Fast

Using the following wrk command, here are the results in hello_world examples for various frameworks

wrk -t12 -c400 -d30s http://127.0.0.1:4321/plaintext
>>> Framework: Cowboy
Requests/sec:  14066.80
Transfer/sec:      1.75MB
>>> Framework: Phoenix/Elixir (prod mode)
Requests/sec:    531.22
Transfer/sec:    131.25KB
>>> Framework: Actix (prod mode)
Requests/sec:  48661.48
Transfer/sec:      6.03MB
>>> Framework: Hyper (prod mode)
Requests/sec:  52909.67
Transfer/sec:      4.44MB
>>> Framework: Thruster (prod mode)
Requests/sec:  53612.10
Transfer/sec:      7.57MB

Intuitive

Based on frameworks like Koa, and Express, thruster aims to be a pleasure to develop with.

Getting Started

The most basic example

extern crate thruster;
extern crate futures;

use std::boxed::Box;
use futures::future;

use thruster::{App, BasicContext as Ctx, MiddlewareChain, MiddlewareReturnValue, Request};

fn generate_context(request: Request) -> Ctx {
  Ctx {
    body: "".to_owned(),
    params: request.params,
    query_params: request.query_params
  }
}

fn plaintext(mut context: Ctx, _chain: &MiddlewareChain<Ctx>) -> MiddlewareReturnValue<Ctx> {
  let val = "Hello, World!".to_owned();
  context.body = val;

  Box::new(future::ok(context))
}

fn main() {
  println!("Starting server...");

  let mut app = App::create(generate_context);

  app.get("/plaintext", vec![plaintext]);

  App::start(app, "0.0.0.0", 4321);
}

Quick setup without a DB

The easiest way to get started is to just clone the starter kit

> git clone git@github.com:trezm/thruster-starter-kit.git
> cd thruster-starter-kit
> cargo run

The example provides a simple plaintext route, a route with JSON serialization, and the preferred way to organize sub routes using sub apps.

Quick setup with postgres

The easiest way to get started with postgres is to install thruster-cli,

> cargo install thruster-cli

And then to run

> thruster-cli init MyAwesomeProject
> thruster-cli component Users
> thruster-cli migrate

Which will generate everything you need to get started! Note that this requires a running postgres connection and assumes the following connection string is valid:

postgres://postgres@localhost/<Your Project Name>

This is all configurable and none of it is hidden from the developer. It's like seeing the magic trick and learning how it's done! Check out the docs for thruster-cli here.

MIT license

Dependencies

Reverse deps