From 391c9098a6947de5c76bf947925a8ead4f1d16a0 Mon Sep 17 00:00:00 2001 From: dqnid Date: Thu, 23 Jan 2025 17:04:06 +0100 Subject: [PATCH] docs: simplest readme --- README.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..79f3abe --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +# Plain HTTP + +This is a simple Rust HTTP library. It provides an `HttpApp` struct that acts as the main structure of the application. + +### Example usage + +```rust +use std::collections::HashMap; + +use plain_http::*; + +fn get_main(_request: HttpRequest) -> HttpAppRouteResponse { + if let Some(body) = _request.body { + println!("Body {}", body); + } + + HttpAppRouteResponse { + body: "hello".to_string(), + content_type: "text", + status: 200, + headers: HashMap::new(), + } +} + +fn get_test(_request: HttpRequest) -> HttpAppRouteResponse { + HttpAppRouteResponse::from_url("./src/assets/index.html") +} + +fn main() { + println!("Hello, world!"); + let mut app = HttpApp { + config: HttpAppConfig { + port: 3000, + max_request_size_bytes: 10000, + ..Default::default() + }, + routes: vec![], + default_headers: HashMap::new(), + }; + + app.add_route(HttpAppRoute { + route: "/".to_string(), + action: Box::new(get_main), + }); + + app.add_route(HttpAppRoute { + route: "/test".to_string(), + action: Box::new(get_test), + }); + + app.start(); +} +```