refactor: migration to library

This commit is contained in:
2025-01-06 00:33:08 +01:00
parent 2b2707d608
commit e006b8dd12
6 changed files with 44 additions and 4 deletions

2
Cargo.lock generated
View File

@@ -3,5 +3,5 @@
version = 3 version = 3
[[package]] [[package]]
name = "rust-http-server" name = "plain-http"
version = "0.1.0" version = "0.1.0"

View File

@@ -1,6 +1,9 @@
[package] [package]
name = "rust-http-server" name = "plain-http"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
description = "Simple http library"
keywords = ["web", "http", "backend", "frontend"]
authors = ["Daniel Heras Quesada"]
[dependencies] [dependencies]

View File

@@ -1,3 +1,3 @@
use super::*; use super::*;
pub fn generate_response(petition: HttpRequest) -> ProcessedResponse {} // pub fn generate_response(petition: HttpRequest) -> ProcessedResponse {}

View File

@@ -1,5 +1,27 @@
use std::collections::HashMap; use std::collections::HashMap;
/*
* App types
* */
pub struct HttpAppConfig {
port: u8,
}
pub type HttpAppRouteFunction = Box<dyn Fn(HttpRequest) -> String>;
pub struct HttpAppRoute<'a> {
route: &'a str,
action: HttpAppRouteFunction,
}
pub struct HttpApp<'a> {
config: HttpAppConfig,
routes: Vec<HttpAppRoute<'a>>,
}
/*
* Parser types
* */
// TODO: // TODO:
// - we could complement status with a struct that stores the status and the error message. // - 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 // - an alternative is to have a status-error_mesage mapper in order to send an error explanation to the client

View File

@@ -3,7 +3,7 @@ use std::net::{SocketAddr, TcpListener};
mod http; mod http;
fn main() { fn principal() {
let addr = SocketAddr::from(([127, 0, 0, 1], 80)); let addr = SocketAddr::from(([127, 0, 0, 1], 80));
let listener = TcpListener::bind(addr).unwrap(); let listener = TcpListener::bind(addr).unwrap();
@@ -20,3 +20,18 @@ fn main() {
_stream.flush().unwrap(); _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);
}
}

0
src/test/basic_get.txt Normal file
View File