Crates.io | rs-express |
lib.rs | rs-express |
version | 0.1.0 |
source | src |
created_at | 2021-08-26 15:00:50.760726 |
updated_at | 2021-08-26 15:00:50.760726 |
description | A port of express-js in Rust |
homepage | |
repository | https://github.com/idan-at/rs-express |
max_upload_size | |
id | 442612 |
size | 56,715 |
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");
}
[dependencies]
rs_express = "0.1.0"
Also, since it is built on top of hyper, it provides (taken from their README)
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
.