#web #http #server #async

mendes

Rust web toolkit for impatient perfectionists

38 releases

0.0.39 Jul 30, 2020
0.0.29 Jun 25, 2020
0.0.21 Mar 1, 2020
0.0.6 Dec 11, 2019
0.0.5 Oct 30, 2019

#49 in HTTP server

Download history 81/week @ 2020-04-14 14/week @ 2020-04-21 6/week @ 2020-04-28 29/week @ 2020-05-12 5/week @ 2020-05-19 23/week @ 2020-05-26 69/week @ 2020-06-02 23/week @ 2020-06-09 101/week @ 2020-06-16 27/week @ 2020-06-23 46/week @ 2020-06-30 30/week @ 2020-07-07 60/week @ 2020-07-14 97/week @ 2020-07-21 98/week @ 2020-07-28

185 downloads per month

MIT/Apache

79KB
2K 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 http::{Response, StatusCode};
use hyper::Body;
use mendes::{dispatch, get, Application, ClientError, 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;

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

    fn error(&self, _: Error) -> Response<Body> {
        Response::builder()
            .status(StatusCode::INTERNAL_SERVER_ERROR)
            .body("ERROR".into())
            .unwrap()
    }
}

#[derive(Debug)]
enum Error {
    Client(ClientError),
}

impl From<ClientError> for Error {
    fn from(e: ClientError) -> Error {
        Error::Client(e)
    }
}

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–5MB
~113K SLoC