https://github.com/thearyanahmed/rusttp
It is the implementation of "Implementing HyperText Transfer Protocol with RUST… maybe?"
https://github.com/thearyanahmed/rusttp
http rust
Last synced: 15 days ago
JSON representation
It is the implementation of "Implementing HyperText Transfer Protocol with RUST… maybe?"
- Host: GitHub
- URL: https://github.com/thearyanahmed/rusttp
- Owner: thearyanahmed
- Created: 2024-07-06T15:33:40.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-09-15T14:48:41.000Z (over 1 year ago)
- Last Synced: 2025-03-30T19:21:59.253Z (11 months ago)
- Topics: http, rust
- Language: Rust
- Homepage: https://thearyanahmed.medium.com/implementing-hypertext-transfer-protocol-with-rust-maybe-f2494281d29c
- Size: 33.2 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# rusttp
rusttp is a simple, lightweight HTTP router built in Rust. It uses the Tokio library for asynchronous I/O and can handle multiple concurrent connections.
This is a learning project to understand how HTTP servers work and how to build one from scratch. It is not intended for production use.
It is the implementation of [https://thearyanahmed.medium.com/implementing-hypertext-transfer-protocol-with-rust-maybe-f2494281d29c](https://thearyanahmed.medium.com/implementing-hypertext-transfer-protocol-with-rust-maybe-f2494281d29c).
## Features
- Supports HTTP methods: GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD
- Route handling with custom logic
- Query parameter parsing
- Header parsing
- Error handling for invalid requests
## Usage
To use rusttp, you need to create a `Router` instance, add routes to it, and then start the server.
Here's a basic example:
```rust
use rusttp::{Method, Request, Response, Router};
use std::sync::Arc;
use std::{fs, io};
#[tokio::main]
async fn main() -> io::Result<()> {
let mut router = Router::new();
router.add_route(Method::GET, "/whoami", who_handler);
router.add_route(Method::GET, "/page", page_handler);
router.add_route(Method::POST, "/say-hi", say_hi_handler);
let router = Arc::new(router);
router
.listen_and_serve("127.0.0.1:8000")
.await
.expect("failed to listen and serve");
Ok(())
}
```
In this example, we're adding several routes to the router. Each route is associated with a handler function that takes a `Request` and returns a `Response`.
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
rusttp is licensed under the MIT license. Please see the `LICENSE` file for more details.