4 releases

0.2.0 Aug 19, 2024
0.1.2 Aug 19, 2024
0.1.0 May 13, 2024
0.0.2 Feb 23, 2024
0.0.1 Nov 25, 2023

#278 in HTTP server

Download history 5/week @ 2024-07-23 5/week @ 2024-07-30 316/week @ 2024-08-13 146/week @ 2024-08-20 1/week @ 2024-08-27 29/week @ 2024-09-10 19/week @ 2024-09-17 6/week @ 2024-09-24 6/week @ 2024-10-01

292 downloads per month

MIT license

41KB
882 lines

mini-server

The mini rust server

cargo add mini-server

HTTP server

use mini_server::*;

fn main() {
    let mut app = HTTPServer::default();

    app.get("/", |_, _| {
        let mut response = HTTPResponse::default();
        response.set_body(b"Hello World!".to_vec());

        response
    });

    app.run();
}

Dynamic paths

The path is an expression that can contains dynamic variables.

  • Basic paths: /, /this/is/a/path, ...
  • Dynamic path: /this/is/a/@varibale, /this/is/another/#variable

# and @ are prefixes for dynamic values. # for denoting numbers and @ for strings

use mini_server::*;

fn main() {
  let mut app = HTTPServer::default();

  app.get("/hello/@name/#age", |_, exprs| {
    let name = expand!(exprs, "name", PathExpr::String);
    let age = expand!(exprs, "age", PathExpr::Number);

    let mut response = HTTPResponse::default();
    response.set_body(
      format!("Hello {name}, you are {age}!")
        .as_bytes()
        .to_vec(),
    );

    response
  });
}

Examples

To run an example:

cargo run --example $name

Dependencies

~120KB