ver 0.1.0

This commit is contained in:
MeexReay 2024-06-17 20:08:40 +03:00
parent a08d53a7a0
commit 4ae756e475
3 changed files with 13 additions and 21 deletions

2
Cargo.lock generated
View File

@ -10,7 +10,7 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
[[package]]
name = "ezhttp"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"futures",
"serde_json",

View File

@ -1,6 +1,6 @@
[package]
name = "ezhttp"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
repository = "https://github.com/MeexReay/ezhttp"

View File

@ -3,12 +3,10 @@ Easy http server on rust
Example:
```rust
use ezhttp::{Headers, HttpResponse, HttpRequest, HttpServer};
use tokio::{runtime::Runtime, net::TcpListener};
use ezhttp::{Headers, HttpRequest, HttpResponse, HttpServer};
struct EzSite {
index_page: String
index_page: String,
}
impl HttpServer for EzSite {
@ -16,21 +14,17 @@ impl HttpServer for EzSite {
println!("{} > {} {}", req.addr, req.method, req.page);
if req.page == "/" {
Some(
HttpResponse::from_str(
Headers::from(vec![
("Content-Type", "text/html")
]),
"200 OK".to_string(),
&self.index_page
)
)
Some(HttpResponse::from_str(
Headers::from(vec![("Content-Type", "text/html")]),
"200 OK".to_string(),
&self.index_page,
))
} else {
None // just shutdown socket
}
}
async fn on_start(&mut self, host: &str, _listener: &TcpListener) {
async fn on_start(&mut self, host: &str) {
println!("Http server started on {}", host);
}
@ -42,7 +36,7 @@ impl HttpServer for EzSite {
impl EzSite {
fn new(index_page: &str) -> Self {
EzSite {
index_page: index_page.to_string()
index_page: index_page.to_string(),
}
}
}
@ -51,9 +45,7 @@ fn main() {
let site = EzSite::new("Hello World!");
let host = "localhost:8080";
Runtime::new().unwrap().block_on(async move {
ezhttp::start_server(site, host).await.unwrap();
});
ezhttp::start_server(site, host).unwrap();
}
```
```