Expand description
§Krustie
Krustie is a very simple backend framework that inspired by Express.js and is designed to be a easy to use.
It is capable of handling requests, routing them to the correct endpoint, modifying the request and response using middlewares, serving static files, and encoding responses using Gzip.
Biggest flaws it has right now is that it is not async and it is not optimized for performance.
Krustie is still in the early stages of development and is not yet ready for production use. The API is subject to change and there may be bugs or missing features.
§Hello World Example
Here is an example of how to create a basic web server using Krustie:
use krustie::{Router, Server, StatusCode};
fn main() {
let mut server = Server::create();
let mut main_router = Router::new();
main_router.get("/", |_, res| {
res.status(StatusCode::Ok).body_text("Hello World!");
});
server.use_handler(main_router);
server.listen(8080);
}
The app starts a server on port 8080
and responds with Hello World!
to any incoming GET request to the root path (/
).
The Router object is used to define the routes and the Server object is used to start the server and listen for incoming requests.
§Running the Server
To run the server, use the following command:
cargo run
When the server is running, you can access it by opening a web browser and navigating to http://localhost:8080
.
§Building the Server
To build the server, use the following command:
cargo build
This will create an executable file in the target/debug
directory.
Modules§
- json
- This module provides utilities for working with JSON data.
- middlewares
- Contains built-in middlewares that can be used with Krustie.
Structs§
- Endpoint
- Holds the route data and the controller function
- Request
- Represents the incoming HTTP request
- Request
Builder - A builder for the
Request
struct - Response
- Represents the response object that will be sent to the client
- Router
- Represents a router that can be used to create a tree of routes
- Server
- Represents the server instance
Enums§
- Handler
Result - Result of the handler
- Http
Method - Represents an HTTP method
- Request
Body - Represents the body of the HTTP request
- Status
Code - Represents the status code of an HTTP response
Traits§
- Middleware
- Trait to be implemented for creating middleware
- Route
Handler - Route handler trait