1 unstable release

0.1.0 Aug 26, 2021

#738 in HTTP server

MIT license

32KB
790 lines

rs-express

rs-express is a simple web framework written in Rust that tries to be as close to Express.js as possible.

The goal of this project is to allow Node.js web developers to easily migrate their web services to Rust, without the hassle of learning a new web framework.

Most APIs will be very similar or even identical to the Node.js version, under the limitations of Rust.

Just to show how similar it can be, here is the Hello World example from express-js github repository:

const express = require('express')
const app = express()

app.get('/', function (req, res) {
  res.send('Hello World')
})

app.listen(3000)

And here is the one in rs-express:

use rs_express::{App, NextFunction, Request, Response};

#[tokio::main]
async fn main() {
    let mut app: App<()> = App::new();

    app.get(
        "/",
        |_req: &mut Request<()>, res: &mut Response, _next: &mut NextFunction| {
            res.send("Hello, World");
        },
    );

    app.listen(3000).await.expect("Failed to listen");
}

Installation

[dependencies]
rs_express = "0.1.0"

Features

  • Familiar API
  • Focus on high performance
  • Simple and easy of use
  • Application level state
  • Simple and robust routing
  • Easy testing capabilities

Also, since it is built on top of hyper, it provides (taken from their README)

  • HTTP/1 and HTTP/2
  • Asynchronous design
  • Leading in performance
  • Tested and correct
  • Extensive production use

Examples

All the examples are under the examples folder.

To run a specific example, run the following command: cargo run --example <example-name>

For example cargo run --example hello-world.

To get a response, use this address: http://localhost:3000 . For example, curl http://localhost:3000/hello will return Hello, World.

Dependencies

~6–9MB
~146K SLoC