8 releases

new 0.1.7 Jan 8, 2025
0.1.6 Jan 6, 2025

#805 in HTTP server

Download history 188/week @ 2024-12-27 566/week @ 2025-01-03

754 downloads per month
Used in 2 crates

MIT license

260KB
4.5K SLoC

Suika Server

Suika Server is a core component for handling HTTP requests and responses in the Suika web stack.

Note: Suika is under active development and not intended for production use. The API is subject to change and may lack comprehensive testing and documentation.

Library Features

  • HTTP Handling
    • Request: Represents an HTTP request.
    • Response: Represents an HTTP response.
    • HttpError: Represents errors that can occur during HTTP handling.
  • Middleware
    • CorsMiddleware: Middleware for handling CORS (Cross-Origin Resource Sharing).
    • FaviconMiddleware: Middleware for serving a favicon.
    • LoggerMiddleware: Middleware for logging HTTP requests and responses.
    • StaticFileMiddleware: Middleware for serving static files.
  • Routing
    • Router: Represents the routing logic for handling different HTTP routes.
  • Server
    • Server: Represents the HTTP server.

Example usage

use suika::server::{Server, Router};
use std::sync::Arc;

pub fn main() {
    let mut server = Server::new("127.0.0.1:8080");
    let mut router = Router::new("/");

    router.get(r"/?$", |_req, res| {
        Box::pin(async move {
            res.set_status(201).await;
            res.body("Hello World!".to_string()).await;
            Ok(())
        })
    });

    server.use_middleware(Arc::new(router));

    server.run();
}

Dependencies

~5–12MB
~128K SLoC