Crates.io | expressrs |
lib.rs | expressrs |
version | 0.1.6 |
source | src |
created_at | 2024-07-03 17:14:02.723622 |
updated_at | 2024-07-06 14:22:28.736324 |
description | Create a website in localhost with ease! |
homepage | |
repository | |
max_upload_size | |
id | 1290770 |
size | 25,308 |
HTTP Localhosts made with ease!
// 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);
});
}
// 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);
});
}
serde_json 1.0
serde { features = ["derive"], version = "1.0" }