Crates.io | arkyo |
lib.rs | arkyo |
version | 0.0.6 |
source | src |
created_at | 2024-02-19 08:38:01.985925 |
updated_at | 2024-03-02 03:22:05.462319 |
description | arkyo is a library for making HTTP Server |
homepage | |
repository | |
max_upload_size | |
id | 1144964 |
size | 23,402 |
Arkyo is a simple HTTP server written in Rust, designed to handle incoming requests and provide appropriate responses based on defined routes and static file serving capabilities.
add_route
method. server.add_route("/example", Method::Get, handler_function);
add_middleware
method. sever.add_middleware("/path", middleware_function)
static_folder
method. server.static_folder("public");
listen
method. server.listen();
use arkyo::prelude::*;
fn main() {
let mut server = Server::new();
// Define routes
server.add_route("/", Method::Get, index_handler);
server.add_route("/about", Method::Get, about_handler);
server.add_route("/user/:id", Method::Get, user_handler);
// Set static folder
server.static_folder("/static");
// Start server
server.listen("127.0.0.1:8080");
}
fn index_handler(_: Request) -> Response {
Response::new()
.status(Status::Ok)
.body("Welcome to Arkyo!")
}
fn about_handler(_: Request) -> Response {
Response::new()
.status(Status::Ok)
.body("Arkyo - A simple HTTP server written in Rust.")
}
fn user_handler(req: Request) -> Response {
let user_id = req.params.get("id").unwrap();
Response::new()
.status(Status::Ok)
.body(format!("User profile page for user {}", user_id))
}
Add arkyo to your Cargo.toml dependencies:
[dependencies]
arkyo = "0.0.6"
This project is licensed under the MIT License - see the LICENSE file for details.
Arkyo - © 2024 DhavyLTS