5 releases
0.1.6 | Jul 6, 2024 |
---|---|
0.1.5 | Jul 5, 2024 |
24 downloads per month
Used in svelte-parser
26KB
568 lines
ExpressRS
HTTP Localhosts made with ease!
Ideas
- Svelte plugin compiler: https://crates.io/crates/svelte-parser
Changelog
- Plugin support
- Query parameter parsing
- URL Decoding
Example
// main.rs
use expressrs::ExpressLib;
fn main() {
let express = ExpressLib::new();
let mut app = express();
// Create a directory called public/ that has index.html and script.js
app.serve_directory("public");
app.get("/", |_, res| {
res.status(200).send_file("public/index.html");
});
app.listen(3030, |port| {
println!("Server listening at http://localhost:{}", port);
});
}
Query parameters example
// main.rs
use expressrs::ExpressLib;
fn main() {
let express = ExpressLib::new();
let mut app = express();
// This will replace the response IF the query parameter is not found
app.get("/:user", |_, res| {
// IS required to be Some() (aka Something)
println!("{:?}", req.queries.get("user"));
// Can be None unless it is added to the query parameters
println!("{:?}", req.queries.get("database"));
});
app.listen(3030, |port| {
println!("Server listening at http://localhost:{}", port);
});
}
Dependencies
serde_json 1.0
serde { features = ["derive"], version = "1.0" }
Dependencies
~0.7–1.6MB
~35K SLoC