| Crates.io | kurosabi |
| lib.rs | kurosabi |
| version | 0.4.7 |
| created_at | 2025-03-21 14:32:23.231215+00 |
| updated_at | 2025-09-14 09:12:29.790039+00 |
| description | A lightweight asynchronous HTTP server framework built on Tokio. |
| homepage | |
| repository | https://github.com/371tti/kurosabi |
| max_upload_size | |
| id | 1600557 |
| size | 178,747 |
jp | (en)
kurosabi is an ultra-lightweight, fast, and simple web backend router that leverages Rust's safety and parallelism.
We value performance, lightweight design, and ease of use.
Critical
If a worker thread panics, it will not restart, and the number of workers will decrease.
If all worker threads are gone, processing will stop.
As a temporary workaround, please avoid causing panics such as by using unwrap.
Add the following to your Cargo.toml:
[dependencies]
kurosabi = "0.4" # Use the latest version
You can see a demo in the examples with the following command:
cargo run --example start
use kurosabi::{Kurosabi, kurosabi::Context};
fn main() {
// Create an instance of Kurosabi
let mut kurosabi = Kurosabi::new();
// Define a route handler like this.
kurosabi.get("/", |mut c| async move {
c.res.text("Hello, Kurosabi!");
c
});
// Define a handler for GET "/field/:field/:value"
// This handler gets the :field and :value parts from the URL path and returns "Field: {field}, Value: {value}" as a text response.
kurosabi.get("/field/:field/:value", |mut c| async move {
let field = c.req.path.get_field("field").unwrap_or("unknown".to_string());
let value = c.req.path.get_field("value").unwrap_or("unknown".to_string());
c.res.text(&format!("Field: {}, Value: {}", field, value));
c
});
// Define a handler for GET "/gurd/*"
// This handler gets the * part from the URL path and returns "Gurd: {path}" as a text response.
// * is a wildcard and accepts any string.
kurosabi.get("/gurd/*", |mut c| async move {
let path = c.req.path.get_field("*").unwrap_or("unknown".to_string());
c.res.text(&format!("Gurd: {}", path));
c
});
// Define a handler for POST "/submit"
// This returns the response data as is.
kurosabi.post("/submit", |mut c| async move {
let body = match c.req.body_form().await {
Ok(data) => data,
Err(e) => {
println!("Error receiving POST data: {}", e);
c.res.set_status(400);
return c;
}
};
c.res.html(&format!("Received: {:?}", body));
c
});
// Define a handler for 404 not found
kurosabi.not_found_handler(|mut c| async move {
let html = html_format!(
"<h1>404 Not Found</h1>
<p>The page you are looking for does not exist.</p>
<p>debug: {{data}}</p>",
data = c.req.header.get_user_agent().unwrap_or("unknown")
);
c.res.html(&html);
c.res.set_status(404);
c
});
// Configure and build the server
let mut server = kurosabi.server()
.host([0, 0, 0, 0])
.port(8082)
.build();
// Run the server
server.run();
}
If you have suggestions, please open an issue.
Pull requests are also welcome.
MIT