#localhost #svelte #website #http #ease #plugin #query

expressrs

Create a website in localhost with ease!

5 releases

0.1.6 Jul 6, 2024
0.1.5 Jul 5, 2024

#1620 in Web programming

Download history 7/week @ 2024-09-11 7/week @ 2024-09-18 8/week @ 2024-09-25 2/week @ 2024-10-02

230 downloads per month
Used in svelte-parser

AGPL-1.0-only

26KB
568 lines

ExpressRS

HTTP Localhosts made with ease!

Ideas

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