RastAPI
RastAPI is an easy-to-use Rust library for creating low-boilerplate, efficient RESTful APIs, inspired by FastAPI (Python). Define route handlers (functions) and map them to their corresponding URLs to get a fully functional API.
RastAPI is designed with Non-Blocking I/O and a Threadpool architecture for efficient and concurrent request handling. It also features an advanced LFU-LRU-based file caching system, leveraging multithreading with lock-stripping techniques to minimize contention.
Features
- Minimal boilerplate for defining routes and handlers.
- High performance leveraging Rust’s concurrency and safety.
- Efficient file uploads and downloads.
Installation
Add the following to your Cargo.toml:
[]
= "0.1.0" # Replace with the latest version
Usage
Text or JSON content
Define routes and handlers to serve text or JSON content using create_response function.
use RastAPI;
use HttpRequest;
use ;
use ContentType;
use HashMap;
// Define a route handler function.
// Signature: fn(request: &HttpRequest, path_params: HashMap<String, String>) -> HttpResponse
File Content
Similarly you can serve file content using send_file. If a file is not found, the server automatically responds with 404 Not Found.
use RastAPI;
use HttpRequest;
use ;
use FileType;
use HashMap;
Future Work
- Don't avoid the rust borrow checker and take it head on. For example using
&strinstead ofString. - Building a more robust logging system.
- Enable encrypted connections (https). Currently it only supports http.
- Impliment security fetures like DDOS protection.
- Building a templating engiene for server side rendering of HTML.
- Enable support for http2. (maybe) Currently it only supports HTTP/1.0 & HTTP/1.1