Expand description
§🔥 afire
§THIS IS AN ALPHA RELEASE FOR v3.0.0
– Its probably not the best idea to use this in production and it will definitely have a lot of breaking changes in the future.
afire is a blazingly fast web server micro framework for rust.
§💠Install
Just add the following to your Cargo.toml
:
[dependencies]
afire = "3.0.0-alpha.3"
§📄 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.
use afire::prelude::*;
let mut server = Server::<()>::new("localhost", 8080);
server.route(Method::GET, "/greet/{name}", |ctx| {
let name = ctx.param("name");
ctx.text(format!("Hello, {}", name))
.content(Content::TXT)
.send()?;
Ok(())
});
server.run().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.
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.
- Contains all the header structs that can be used with HTTP requests and responses.
- 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 types and traits that are commonly used in most afire applications.
- Protocol implementations.
- Stuff for defining routes and error handling in routes. Holds
RouteContext
andAdditionalRouteContext
, which are used to add context to errors. The context can include a message, status code, and headers. - Server-sent event (SSE) support.
- This is afire’s built-in logging system. Enabled with the
tracing
feature (enabled by default). The default log level isLevel::Error
. - WebSocket support.
Macros§
- Simple logging system. See
crate::trace
for more information.
Structs§
- A collection of data important for handling a request. It includes both the request data, and a reference to the server. You also use it to build and send the response.
- 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 server.
- Represents a Set-Cookie header. Has more information than a normal Cookie (e.g. max-age, domain, path, secure).
Enums§
- Common MIME types for HTTP responses. Used with the
crate::Context::content
andcrate::Response::content
methods. - HTTP header names.
- HTTP Methods.
- HTTP status codes.
Traits§
- Trait used to implement Middleware, which is code that runs before and after the routes - potentially modifying the request and response. You can use Middleware to Log Requests, Ratelimit Requests, add Analytics, etc.