42 releases

0.4.0 Feb 12, 2024
0.2.1 Jul 25, 2023
0.2.0 Mar 21, 2023
0.1.1 Aug 8, 2022
0.0.18 Mar 1, 2020

#1435 in Procedural macros

Download history 27/week @ 2023-12-15 2/week @ 2023-12-22 46/week @ 2024-01-05 67/week @ 2024-01-12 56/week @ 2024-01-19 15/week @ 2024-01-26 13/week @ 2024-02-02 93/week @ 2024-02-09 97/week @ 2024-02-16 64/week @ 2024-02-23 62/week @ 2024-03-01 36/week @ 2024-03-08 20/week @ 2024-03-15 314/week @ 2024-03-29

377 downloads per month
Used in 2 crates

MIT/Apache

30KB
717 lines

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::IntoResponse;
use mendes::http::request::Parts;
use mendes::http::{Response, StatusCode};
use mendes::{handler, route, Application, Context};

#[handler(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;

    async fn handle(mut cx: Context<Self>) -> Response<Body> {
        route!(match cx.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 IntoResponse<App> for Error {
    fn into_response(self, _: &App, _: &Parts) -> 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

~300–750KB
~18K SLoC