Thruster
An opinionated framework for web development in rust.
Motivation
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
>>> 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
If you have cargo generate
installed, you can simply run the cargo generator
cargo generate --git https://github.com/ami44/thruster-basic-template.git --name myproject
The most basic example
extern crate thruster;
extern crate futures;
use Box;
use future;
use ;
use Server;
use ThrusterServer;
The most basic example with Hyper
extern crate thruster;
extern crate futures;
extern crate hyper;
use Box;
use future;
use ;
use ;
use Server;
use ;
use ThrusterServer;
Quick setup without a DB
The easiest way to get started is to just clone the starter kit
> git
> cd
> cargo
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
And then to run
> thruster-cli
> thruster-cli
> thruster-cli
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.
Testing
Thruster provides an easy test suite to test your endpoints, simply include the testing
module as below:
let mut app = new_basic;
...
app.get;
...
let result = get;
assert!;
Other, or Custom Backends
Thruster is capable of just providing the routing layer on top of a server of some sort, for example, in the Hyper snippet above. This can be applied broadly to any backend, as long as the server implements ThrusterServer
.
There needs to be:
- An easy way to new up a server.
- A function to start the server.
Within the start
function, the server implementation should:
- Start up some sort of listener for connections
- Call
let matched = app.resolve_from_method_and_path(<some method>, <some path>);
(This is providing the actual routing.) - Call
app.resolve(<incoming request>, matched)
(This runs the chained middleware.)