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.0.0"

📄 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 fine 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

pub use self::error::Error;
pub use self::middleware::Middleware;

Modules

Errors that can occur in the process of connecting to clients, parsing HTTP and handling requests.
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.
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!
Basic built-in logging system

Macros

Simple logging system. See crate::trace for more information.

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

Common MIME types.
Common HTTP headers. Just the ‘common’ ones, which are ones that I use semi-frequently, or that are used internally.
HTTP Methods. Also contains a special method (ANY) for routes that run on all methods, which will never be the method of a request. From https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods.
HTTP status codes. Used to indicate the status of an HTTP response. Note: Methods that accept a Status will also accept any u16 value, converting it to a Status::Custom if it is not a valid status code.