🔥 afire
A blazing fast web framework for Rust
💠 Install
Just add the following to your Cargo.toml
:
[]
= "0.1.3"
📄 Info
This is kinda like express.js for rust. It is not that complicated but it still makes development of apis / servers much easier. It supports Middleware and comes with some built in for Logging and Rate limiting.
For more information on this lib check the docs here
💥 Examples
Make a simple server:
// Import Lib
use *;
// Create Server
let mut server: Server = new;
// Add a route
server.route;
// Start the server
// This is blocking
server.start;
You can add as many routes as you want. The most recently defined route will always take priority. So you can make a 404 page like this:
// Import Library
use ;
// Create Server
let mut server: Server = new;
// Define 404 page
// Because this is defined first, it will take a low priority
server.all;
// Define a route
// As this is defined last, it will take a high priority
server.route;
// Starts the server
// This is blocking
server.start;
📦 Middleware
afire comes with some builtin extensions in the form of middleware.
• ⛓️ Rate-limit
This will use the client ip to limit the amount of requests that will be processed. You can configure the request limit and the reset period.
// Import Stuff
use ;
// Make server
let mut server: Server = new;
// Enable Rate Limiting
// This will limit the requests per ip to 5 every 10 sec
attach;
• 📜 Logger
This will log all requests to a file or stdout or bolth. You can pick a log level that will determine if headers and body will be logged.
// Import Stuff
use ;
// Make server again
let mut server: Server = new;
// Enable Logger
// Level::Debug has headers and body
// Level::Info does not
attach;