diff --git a/Cargo.lock b/Cargo.lock index e3e2167..9f88dc7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,5 +3,5 @@ version = 3 [[package]] -name = "rust-http-server" +name = "plain-http" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index cb0fd0a..8915a87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,9 @@ [package] -name = "rust-http-server" +name = "plain-http" version = "0.1.0" edition = "2021" +description = "Simple http library" +keywords = ["web", "http", "backend", "frontend"] +authors = ["Daniel Heras Quesada"] [dependencies] diff --git a/src/http/generators.rs b/src/http/generators.rs index b562688..0763a41 100644 --- a/src/http/generators.rs +++ b/src/http/generators.rs @@ -1,3 +1,3 @@ use super::*; -pub fn generate_response(petition: HttpRequest) -> ProcessedResponse {} +// pub fn generate_response(petition: HttpRequest) -> ProcessedResponse {} diff --git a/src/http/types.rs b/src/http/types.rs index 0a669f6..6be0836 100644 --- a/src/http/types.rs +++ b/src/http/types.rs @@ -1,5 +1,27 @@ use std::collections::HashMap; +/* + * App types + * */ +pub struct HttpAppConfig { + port: u8, +} + +pub type HttpAppRouteFunction = Box String>; + +pub struct HttpAppRoute<'a> { + route: &'a str, + action: HttpAppRouteFunction, +} + +pub struct HttpApp<'a> { + config: HttpAppConfig, + routes: Vec>, +} + +/* + * Parser types + * */ // TODO: // - we could complement status with a struct that stores the status and the error message. // - an alternative is to have a status-error_mesage mapper in order to send an error explanation to the client diff --git a/src/main.rs b/src/lib.rs similarity index 71% rename from src/main.rs rename to src/lib.rs index 7b7981a..8b9fd2e 100644 --- a/src/main.rs +++ b/src/lib.rs @@ -3,7 +3,7 @@ use std::net::{SocketAddr, TcpListener}; mod http; -fn main() { +fn principal() { let addr = SocketAddr::from(([127, 0, 0, 1], 80)); let listener = TcpListener::bind(addr).unwrap(); @@ -20,3 +20,18 @@ fn main() { _stream.flush().unwrap(); } } + +pub fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn it_works() { + let result = add(2, 2); + assert_eq!(result, 4); + } +} diff --git a/src/test/basic_get.txt b/src/test/basic_get.txt new file mode 100644 index 0000000..e69de29