14 releases (2 stable)

1.1.0 Apr 10, 2022
1.0.0 Mar 15, 2022
0.4.0 Feb 19, 2022
0.2.2 Dec 5, 2021
0.2.0 Nov 4, 2021

#49 in HTTP server

Download history 44/week @ 2022-01-24 58/week @ 2022-01-31 18/week @ 2022-02-07 49/week @ 2022-02-14 35/week @ 2022-02-21 6/week @ 2022-02-28 9/week @ 2022-03-07 75/week @ 2022-03-14 49/week @ 2022-03-21 6/week @ 2022-03-28 121/week @ 2022-04-04 32/week @ 2022-04-11 13/week @ 2022-04-18 49/week @ 2022-04-25 135/week @ 2022-05-02 27/week @ 2022-05-09

227 downloads per month
Used in afire_compress

GPL-3.0 license

120KB
2.5K SLoC

🔥 afire Crates.io

A blazing fast dependency free web framework for Rust

💠 Install

Just add the following to your Cargo.toml:

[dependencies]
afire = "1.1.0"

📄 Info

This is kinda like express.js for rust. It is not that complicated but it still makes development of apis / web servers much easier. It supports Middleware and comes with some built in for Static File Serving, Logging and Rate limiting.

For more information on this lib check the docs here

💥 Examples

For some examples go here.

Here is a super simple example:

// Import Lib
use afire::{Server, Method, Response, Header, Content};

// Create Server
let mut server: Server = Server::new("localhost", 8080);

// Add a route
server.route(Method::GET, "/greet/{name}", |req| {
  let name = req.path_param("name").unwrap();

  Response::new()
    .text(format!("Hello, {}", name))
    .content(Content::TXT)
});

// Start the server
// This is blocking
server.start().unwrap();

🔧 Features

Here I will outline interesting features that are available in afire.

  • Builtin Middleware

afire comes with some builtin extensions in the form of middleware. Currently the builtin middleware includes rate_limit, logging, and serve_static. For these you will need to enable the features.

To use these extra features enable them like this:

afire = { version = "1.1.0", features = ["rate_limit", "logging", "serve_static"] }
  • Content Types

As an easy way to set the Content-Type of a Response you can use the .content methood of the Response. Then you can put one of the common predefined types.

// Import Lib
use afire::{Server, Method, Response, Header, Content};

// Create Server
let mut server: Server = Server::new("localhost", 8080);

// Add a route
server.route(Method::GET, "/", |_req| {
  Response::new()
    .text("Hello, World!")
    .content(Content::TXT)
});

// Start the server
// This is blocking
server.start().unwrap();

/// Prelude

No runtime deps