micro_http_async
What is it for?
A small, lightweight crate using async to serve web pages or webapis with high performance and low overhead.
How do I use it?
Firstly, install the crate and dependencies:
= "*"
tokio = "1.1"
micro_http_async
This crate is designed to abstract away many of the low level code required to run a safe, asynchrynous web server
Here is a small example which shows how to route, use asynchrynous callbacks and load webpage templates from HTML files.
For the HTML files included, please go to the repository and check the templates
folder.
Static files also included.
To run the included example (which is the example seen below), run cargo run --example hello_world
, and visit 127.0.0.1:8080
Please note this is probably not the final API
Example
/// Small example to show the functionings of the crate. Read the comments to see how everything
/// functions
use HttpServer;
use Request;
use HtmlConstructor;
use Vars;
use Variable;
use Response;
/// # main handler
///
/// main handler is a test to test our route and function callbacks work
///
/// And it does!
///
/// The way it works is that we run test_handler when we recieve a connection.
///
/// Then, this handler manipulates the request (for post info, or other info etc)
///
/// after, we return the response as a string. It is then served to the user.
///
/// The syntax is a bit weird but if it works it works. I'll try fix it :')
///
/// It should return a pinned box future result that implements send
/// We have to define a custom error handler, which defines what to do when we have a 404
///
/// Not doing this WILL result in an unrecoverable panic.
/// # main
///
/// Does what it says, just sets up the server and routes
///
/// then listens for incoming connections
pub async
This crate aims only to simplify webapi or lightweight web creation - not intended to run full scale web apps like chatrooms or other high intensity applications. It implements a simple asynchrynous routing system (Made using hashmaps for speed and efficiency) as well as asynchrynous file loading and more.
The demo above uses 0% CPU under no load, and less than 10mb of memory under usage