summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorTyler Murphy <tylerm@tylerm.dev>2023-07-05 22:02:34 -0400
committerTyler Murphy <tylerm@tylerm.dev>2023-07-05 22:02:34 -0400
commit732d7d83068efb5a44ab185716d3ad0001c40f5a (patch)
tree5799073d937631ecd72dd442deb3b72be5e6afa8 /README.md
parentchanges (diff)
downloadhttp-732d7d83068efb5a44ab185716d3ad0001c40f5a.tar.gz
http-732d7d83068efb5a44ab185716d3ad0001c40f5a.tar.bz2
http-732d7d83068efb5a44ab185716d3ad0001c40f5a.zip
readme
Diffstat (limited to 'README.md')
-rw-r--r--README.md38
1 files changed, 38 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..4ee8997
--- /dev/null
+++ b/README.md
@@ -0,0 +1,38 @@
+# http
+
+A rust http parsing library
+
+### Example
+
+```rs
+use http::{request::Request, parse::TryParse, error::HTTPError, response::Response, status, header::HeaderName};
+
+fn main() -> Result<(), HTTPError> {
+
+ // http request as a string
+ let request_str = "GET / HTTP/1.1\n\
+ Host: www.example.com\n\
+ User-Agent: Mozilla/4.0\n\
+ Accept-language: en\n\
+ \n\
+ ";
+
+ // here we set what we want the body to be parsed into if it exists
+ // the body type must implement FromStr and ToString
+ let request = Request::<String>::try_parse(request_str)?; // try parse since it can fail
+
+ let mut response = Response::<String>::new(); // create a new response
+ response
+ .set_body("hello world!") // add a body that is Into<T>
+ .set_status(status::SUCCESS) // set the status
+ .add_header((HeaderName::try_from("Content-Type")?, "text/plain")); // set content-type header
+
+ let response_str = response.to_string(); // get http response in text form
+
+ Ok(())
+}
+```
+
+### License
+
+This project is licensed under the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html)