From c0aeee42dbb185877d93040a936a253104626728 Mon Sep 17 00:00:00 2001 From: myyrakle Date: Fri, 11 Oct 2024 00:12:40 +0900 Subject: [PATCH] =?UTF-8?q?[#161]=20index=20=EB=AC=B8=EC=84=9C=20=EC=BD=94?= =?UTF-8?q?=EB=A9=98=ED=8A=B8=20=EB=B3=B4=EC=99=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rupring/src/lib.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/rupring/src/lib.rs b/rupring/src/lib.rs index b21ec24..266a088 100644 --- a/rupring/src/lib.rs +++ b/rupring/src/lib.rs @@ -31,10 +31,43 @@ fn main() { # Request - rupring defines HTTP Request through [crate::request::Request] type and provides convenient request processing using macros. +```rust +#[rupring::Get(path = /:id)] +pub fn hello(request: rupring::Request) -> rupring::Response { + let method = request.method; + assert_eq!(method, rupring::Method::GET); + + let path = request.path; + assert_eq!(path, "/"); + + let body = request.body; + assert_eq!(body, ""); + + let headers = request.headers; + let content_type = headers.get("content-type").unwrap(); + assert_eq!(content_type, "text/plain"); + + let id = request.path_parameters["id"].clone(); + assert_eq!(id, "123"); + + let query = request.query_parameters["query"].clone(); + assert_eq!(query, vec!["asdf".to_string()]); + + //... + + response +} +``` - Please refer to the corresponding [document](crate::request) for more details. # Response - rupring defines HTTP Response through [crate::response::Response] type and provides convenient response processing using macros. +```rust +#[rupring::Get(path = /)] +pub fn hello(_request: rupring::Request) -> rupring::Response { + rupring::Response::new().text("Hello, World!".to_string()) +} +``` - Please refer to the corresponding [document](crate::response) for more details. # Middleware