# nanohttp **Repository Path**: mschan/nanohttp ## Basic Information - **Project Name**: nanohttp - **Description**: No description available - **Primary Language**: Rust - **License**: MIT - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-11-16 - **Last Updated**: 2023-11-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # nanohttp `nanohttp` is a small zero-dependency library to parse http requests and build valid http responses. It is intended purely as an implementation of the HTTP protocol, and therefore does not handle things like routing, json serialization and deserialization, or building a HTTP server. See the examples below for how you can use it in combination with a TCP server and a runtime library such as [tokio](https://docs.rs/tokio/latest/tokio/) or [async-std](https://docs.rs/async-std/latest/async_std/) to build a custom HTTP server. This library is intended to abstract away the details of dealing with HTTP, without removing the need to understand how HTTP works at a high level. For example there are a few helper methods which will automatically set relevant headers. But for the most part, it is up to the consumer of the library to ensure that the correct headers are set, and generally ensure that the constructed HTTP response is valid. An example of this is ensuring that the `Location` header is set when returning a `303` response code. ## Examples Parse an incoming HTTP request. ```rust use nanohttp::{Request, Method}; let req = "GET / HTTP/1.1\r\n"; let res = Request::from_string(req).unwrap(); assert_eq!(res.method, Method::GET); assert_eq!(res.path.uri, "/"); ``` Build a HTTP response, and convert it to a valid HTTP message. ```rust use nanohttp::{Response, Status, Header}; let html = "