Expand description
Sailboat
The problem
The rust http server framework genre seems to be filled with a large overuse of macros to produce framework structures that are essentially a sub-language of rust.
The solution
Sailboat is focused on simplicity while still maintaining speed. This library avoids complex, unclear, or otherwise unnecessary macros preferring instead to write (at times) more verbose yet clear; clean code.
Checklist
Order of tasks not necessarily in order of completion
-
Basic routing
-
URL parameters
-
Multithreading responses
-
Application wide resources/context
-
Websockets
-
Move to async
-
Ssl/Https
-
Optimizations
-
Custom Http implementation
Example
Run examples using cargo run --example example_name
A basic hello world program using sailboat:
use sailboat::{
application::Application,
executor::DefaultExecutor,
request::Request,
response::Response,
service::{Command, Point},
StatusCode,
};
type Data = ();
async fn hello_world<'a>(_req: &mut Request<'a>, _ctx: &Data) -> Command<Data> {
// Responding with `None` will act as a middleware System
// Responding with `Some` will respond to the request object and move on to the next request
// All systems registered after receiving a `Some` will not be run
Command::Respond(Response::empty(StatusCode(200)))
}
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let root = Point::root().fold(|s| {
// `localhost/hello_world`
s.push_child(Point::with_system(
"hello_world",
hello_world,
))
});
// The application will automatically respond to all unrecognized urls with a `StatusCode(404)` not found
// In this case, the only recognized url is `localhost/hello_world`
let app = Application::<DefaultExecutor>::new("0.0.0.0:8080", root, ())?;
// Initiate main application loop
let _ = app.run();
Ok(())
}
Performance
On my personal computer using wrk -t 4 -c 4
A basic hello_world example revealed the following
sailboat: ~240k req/sec actix: ~280k req/sec tiny_http: ~280k req/sec rouille: ~80k req/sec
Documentation
Currently not on crates until 0.1.0 release
generate docs using cargo doc --open
Licensing
See LICENSE-MIT
Modules
Structs
- Represents a HTTP header.
- Status code of a request or response.
Enums
- HTTP request methods