#web #http #server #async

mendes

Rust web toolkit for impatient perfectionists

53 releases

0.0.55 Apr 26, 2021
0.0.54 Mar 8, 2021
0.0.53 Feb 1, 2021
0.0.52 Nov 19, 2020
0.0.5 Oct 30, 2019

#36 in HTTP server

Download history 95/week @ 2021-02-23 206/week @ 2021-03-02 231/week @ 2021-03-09 157/week @ 2021-03-16 192/week @ 2021-03-23 233/week @ 2021-03-30 213/week @ 2021-04-06 131/week @ 2021-04-13 174/week @ 2021-04-20 24/week @ 2021-04-27 79/week @ 2021-05-04 37/week @ 2021-05-11 180/week @ 2021-05-18 41/week @ 2021-05-25 113/week @ 2021-06-01 288/week @ 2021-06-08

855 downloads per month

MIT/Apache

96KB
2.5K SLoC

Mendes: web toolkit for impatient perfectionists

Documentation Crates.io Build status Coverage status License: MIT License: Apache 2.0

Mendes is a Rust web toolkit for impatient perfectionists (apologies to Django). It aims to be:

  • Modular: less framework, more library; pick and choose components
  • Async: async/await from the start
  • Low boilerplate: easy to get started, but with limited "magic"
  • Type-safe: leverage the type system to make error handling low effort
  • Secure: provide security by default; no unsafe code in this project
  • Run on stable Rust (no promises on MSRV though)

Mendes is currently in an extremely early phase and probably not ready for anything but experiments for those who are curious. Feedback is always welcome though!

Minimal example

This should definitely become more minimal over time.

use async_trait::async_trait;
use hyper::Body;
use mendes::application::Responder;
use mendes::http::{Response, StatusCode};
use mendes::{get, route, Application, Context};

#[get]
async fn hello(_: &App) -> Result<Response<Body>, Error> {
    Ok(Response::builder()
        .status(StatusCode::OK)
        .body("Hello, world".into())
        .unwrap())
}

struct App {}

#[async_trait]
impl Application for App {
    type RequestBody = ();
    type ResponseBody = Body;
    type Error = Error;

    #[route]
    async fn handle(mut cx: Context<Self>) -> Response<Body> {
        path! {
            _ => hello,
        }
    }
}

#[derive(Debug)]
enum Error {
    Mendes(mendes::Error),
}

impl From<mendes::Error> for Error {
    fn from(e: mendes::Error) -> Self {
        Error::Mendes(e)
    }
}

impl From<&Error> for StatusCode {
    fn from(e: &Error) -> StatusCode {
        let Error::Mendes(e) = e;
        StatusCode::from(e)
    }
}

impl Responder<App> for Error {
    fn into_response(self, _: &App) -> Response<Body> {
        let Error::Mendes(err) = self;
        Response::builder()
            .status(StatusCode::from(&err))
            .body(err.to_string().into())
            .unwrap()
    }
}

All feedback welcome. Feel free to file bugs, requests for documentation and any other feedback to the issue tracker.

Mendes was created and is maintained by Dirkjan Ochtman.

Dependencies

~0.4–6.5MB
~155K SLoC