Crates.io | sailboat |
lib.rs | sailboat |
version | 0.1.0+1 |
source | src |
created_at | 2023-03-16 23:06:23.518703 |
updated_at | 2023-03-16 23:10:17.989093 |
description | Simplicity focused http framework providing ergonomic and fast bindings. |
homepage | |
repository | https://github.com/Kay-Conte/sailboat |
max_upload_size | |
id | 812138 |
size | 42,927 |
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.
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.
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
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(())
}
On my personal computer using wrk -t 4 -c 4
A basic hello_world example revealed the following
This crate aims to be 100% fully documented.
See LICENSE-MIT