Crate afire

source ·
Expand description

🔥 afire Crates.io

afire is a blazingly fast web server micro framework for rust.

💠 Install

Just add the following to your Cargo.toml:

[dependencies]
afire = "2.2.1"

📄 Info

afire is a simple synchronous multithreaded express.js inspired rust web micro framework. wow that was long. It comes with some built extensions in for Static File Serving, Rate limiting, and more.

Below you can find links to some afire related resources.

💥 Example

For more examples see the examples directory here.

Below is a super simple example so you can see the basics of afire syntax.

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

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

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

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

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

💼 License

afire is licensed under the MIT license so you are free to do basically whatever you want with it as long as you add a copyright notice. You can read the full license text here.

Re-exports

Modules

  • Cookies! This module provides a simple interface for setting and receiving cookies.
  • Errors that can occur in the process of connecting to clients, parsing HTTP and handling requests.
  • Useful extensions to the base afire. Includes helpful middleware like Serve Static, Rate Limit and Logger.
  • HTTP headers.
  • Internal Functions
  • Middleware is code that runs before and after the routes. They can be used to Log Requests, Ratelimit Requests, add Analytics, etc. For more information, see the Middleware Example.
  • Multipart request parsing.
  • The Prelude is a collection of very commonly used things in afire. Unless you are using middleware, extensions or internal lower level stuff this should be all you need!
  • Server-sent event (SSE) support.
  • Basic built-in logging system

Macros

Structs

  • Represents a Cookie
  • Http header. Has a name and a value.
  • Collection of query parameters. Can be made from the query string of a URL, or the body of a POST request. Similar to crate::header::Headers.
  • Http Request
  • Http Response
  • Defines a route.
  • Defines a server.
  • Represents a Set-Cookie header. Has more information than a normal Cookie (e.g. max-age, domain, path, secure).

Enums