A boilerplate++ for a minimal rust web backend

Overview

Boiler room

A boilerplate++ for a minimal rust web backend

Just fork/clone/download this repo and build your backend on it.

Why?

Both routing and error handling in rust's web frameworks feel needlessly abstracted and complex. In an attempt to make a web-backend that feels natural to me I wrote this boilerplate where Result<Response,Error> is cleanly converted into a correct Response and where routing is a tree structure.

Structure:

  • The main.rs file. Do I need to tell you? Defines running the application.
  • The state.rs file defines the state struct shared between async workers and its init.
  • The traits.rs file defines the trait that allows converting from Result<Response, Error> to Response.
  • The error.rs file defines Error, and implements the trait from traits.rs on it.
  • The routes directory handles everything routing.
    • mod.rs starts the routing.
    • The utils directory contains utility functions for:
      • routing.rs parsing and validating routing
      • request.rs parsing and validating request data
      • response.rs constructing and modifying responses
    • Other directories under routes are new web-routes. The idea is that they have a route function that takes state, req, path_vec which then either returns a response or hands down into another route function. All in all resulting in a match tree structure matching the modules.

How to use:

Change license:

  • Replace LICENSE.md
  • Change license field in Cargo.toml

Adding crates:

  • Add to Cargo.toml
  • Add relevant error types to error.rs
  • Add relevant variable and init into state.rs

Adding routes:

The routing is intended to be done one "folder" at a time, so adding a route is easiest when it is one step from an existing one. In that case:

  • Create a route function (potentially skip needless arguments)
  • Add a match case to the nearest route function for the path you wish to add
  • Make that match case run that route function.

If the new path is more than one step from the nearest one you need to make a choice. Either you create multiple matches to get to the path you want, or you throw out my routing design in favour of the classic full-path matching. Especially consider if your path structure is more continuous than not. If more not, my tree routing is not for you.

License

Licensed under either of these:

You might also like...
Paru is your standard pacman wrapping AUR helper with lots of features and minimal interaction.

Paru Feature packed AUR helper Description Paru is your standard pacman wrapping AUR helper with lots of features and minimal interaction. Installatio

A minimal discord api wrapper.

descord Descord is a discord api wrapper. Example use descord::prelude::*; #[tokio::main] async fn main() { let mut client = Client::new(

Playing with web dev in Rust. This is a sample Rust microservice that can be deployed on Kubernetes.

Playing with web dev in Rust. This is a sample Rust microservice that can be deployed on Kubernetes.

Benchmarking web frameworks written in rust with rewrk tool.

Web Framework Benchmarks Benchmarking web frameworks written in rust with rewrk tool.

simple lottery maker made with rust, just web framework

Toy project for fun It's just for fun! making plausible lottery numbers for Korea made with rust This lottery web framework generates and presents pla

Web Browser Engineering

This is a port of Web Browser Engineering series from Python to Rust done by Korean Rust User Group.

Blueboat is an open-source alternative to Cloudflare Workers. The monolithic engine for serverless web apps.

Blueboat Blueboat is an open-source alternative to Cloudflare Workers. Blueboat aims to be a developer-friendly, multi-tenant platform for serverless

Web service for Firefox Suggest

Merino A service to provide address bar suggestions to Firefox. For more details, see the service docs. About the Name This project drives an importan

Software adapter for various Chunithm slider controllers with a built-in Brokenithm web controller
Software adapter for various Chunithm slider controllers with a built-in Brokenithm web controller

slidershim Software adapter for various Chunithm slider controllers with a built-in Brokenithm web controller. Has support for keyboard/gamepad output

Owner
null
One-Stop Solution for all boilerplate needs!

One Stop Solution for all boilerplate needs! Consider leaving a ⭐ if you found the project helpful. Templa-rs Templa-rs is a one-of-a-kind TUI tool wr

IEEE VIT Student Chapter 27 Aug 28, 2022
A backend API starter with Rust & postgres

Rust backend starter Rust backend starter with OpenAPI spec & swagger with rocket_okapi

Ilkka Poutanen 3 Feb 1, 2022
unFlow is a Design as Code implementation, a DSL for UX & backend modeling. DSL to Sketch file, Sketch to DSL, DSL to code.

unflow 是一个低代码、无代码设计语言。unFlow is a Design as Code implementation, a DSL for UX & backend modeling. DSL to Sketch file, Sketch to DSL, DSL to code.

Inherd OS Team (硬核开源小组) 70 Nov 27, 2022
The 峨眉 (EMei) JIT/AOT backend framework.

emei The 峨眉 (EMei) JIT/AOT backend framework. Support Instructions x86_64 mov mov mov_zero_extend_bit8/16 mov_sign_extend_bit8/16/32 mov_rev movs(is m

Lyzh 14 Apr 11, 2022
A Litecord compatible/inspired OSS implementation of Discord's backend for fun and profit.

A Litecord compatible/inspired OSS implementation of Discord's backend for fun and profit.

Evie Viau 3 May 9, 2022
The first fully opensource Skyblock mod backend lol.

DWS The first fully opensource Skyblock mod backend lol. Running Features Rest GET /cosmetics POST /broadcast GET /metrics GET /users DELETE /users?uu

null 2 Jan 2, 2023
⚡rustygram is a minimal and blazing fast telegram notification framework for Rust

⚡rustygram ⚡rustygram is a minimal and blazing fast telegram notification framework using Rust. Abstracts away the Telegram API complexity so your app

Chia Yong Kang 15 Dec 1, 2023
My Minimal Fasta Toolkit

My (Max's?) Minimal Fasta Toolkit Nothing sophisticated. Minimal, simple fasta tools. It's stuff that's been done many times, but this way I can get i

tolkit 3 Sep 15, 2022
Minimal cargo but for c/c++

Introduction We all love cargo, having an idea, do cargo new, type our idea and cargo r, easy right? Well... sometimes you want to do that in C or C++

cdecompilador 6 Oct 31, 2022
A minimal RedDSA implementation for use in Zebra and zcashd.

A minimal RedDSA implementation for use in Zcash. Two specializations of RedDSA are used in Zcash: RedJubjub and RedPallas. For each of these, two par

Zcash Foundation 3 Jul 30, 2022