refactor: migration to library
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -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"
|
||||||
|
|||||||
@@ -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]
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
pub fn generate_response(petition: HttpRequest) -> ProcessedResponse {}
|
// pub fn generate_response(petition: HttpRequest) -> ProcessedResponse {}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
0
src/test/basic_get.txt
Normal file
Reference in New Issue
Block a user