2 releases
0.1.3 | Feb 4, 2023 |
---|---|
0.1.2 | Feb 4, 2023 |
0.1.1 |
|
0.1.0 |
|
22 downloads per month
7KB
83 lines
a crate for making a customizable http web server, similar to express from node.js or bao from bun.js
example:
use haws::handlers::{ AppHandler };
use haws::types::{ RequestBuffer };
fn main() {
fn index(_buffer: RequestBuffer) -> String {
return "<h1>Hello world</h1>".to_string();
}
fn err_page(_buffer: RequestBuffer) -> String {
return "<h1>404 page not found</h1>".to_string();
}
let mut app = AppHandler::new("localhost".to_string(), 3000);
// if you put a '/' in the path paramater then every time the client navigates to the root of the page or just "localhost:3000" not "localhost:3000/home" or anything like that just the root no extra path after "localhost:3000", once you navigate to this route it will return the html in the dest attribute
app.route("/".to_string(), &index);
// if you put a '.' in the path paramater then every time the client navigates to a route that doesn't exist it will return the html in the dest attribute
app.route(".".to_string(), &err_page);
app.serve();
}
The module that contains all the handler structs The module that contains all the types and type aliases
Dependencies
~0–9.5MB
~42K SLoC