https://github.com/burdockcascade/libhttp
Lightweight low-level HTTP Server library
https://github.com/burdockcascade/libhttp
http rust server
Last synced: 11 months ago
JSON representation
Lightweight low-level HTTP Server library
- Host: GitHub
- URL: https://github.com/burdockcascade/libhttp
- Owner: burdockcascade
- License: mit
- Archived: true
- Created: 2024-04-21T19:29:01.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-05T20:58:11.000Z (over 1 year ago)
- Last Synced: 2025-03-11T04:32:45.092Z (about 1 year ago)
- Topics: http, rust, server
- Language: Rust
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# libhttp
## Description
a lightweight low-level http server library for rust
## Usage
```rust
use std::sync::{Arc, Mutex};
use libhttp::http::{CONTENT_TYPE_TEXT_PLAIN, HEADER_CONTENT_TYPE, Status};
use libhttp::message::{HttpRequest, HttpResponse};
use libhttp::server::{HttpHandler, HttpServer};
fn main() {
HttpServer::builder()
.hostname("127.0.0.1")
.port(80)
.handler(Arc::new(Mutex::new(MyHandler { counter: 0 })))
.start()
.expect("server to run successfully")
}
struct MyHandler {
counter: u32,
}
impl HttpHandler for MyHandler {
fn handle(&mut self, request: &HttpRequest) -> HttpResponse {
self.counter += 1;
let body = format!("Hello, world! {}", self.counter).as_bytes().to_vec();
return HttpResponse::builder()
.status(Status::Ok)
.header(HEADER_CONTENT_TYPE, CONTENT_TYPE_TEXT_PLAIN)
.body(body)
.build()
}
}
```