From d2982531bdaa169168c243a1f811973f33606821 Mon Sep 17 00:00:00 2001 From: yhirose Date: Tue, 5 Dec 2017 19:30:13 -0500 Subject: [PATCH] Updated README --- README.md | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 01e364d..2ed1de9 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@ A C++11 header-only HTTP library. It's extremely easy to setup. Just include **httplib.h** file in your code! +Inspired by [Sinatra](http://www.sinatrarb.com/) and [express](https://github.com/visionmedia/express). + Server Example -------------- -Inspired by [Sinatra](http://www.sinatrarb.com/) and [express](https://github.com/visionmedia/express). - ```c++ #include @@ -71,9 +71,24 @@ svr.set_error_handler([](const auto& req, auto& res) { }); ``` +### `multipart/form-data` POST data + +```cpp +svr.post("/multipart", [&](const auto& req, auto& res) { + auto size = req.files.size(); + auto ret = req.has_file("name1")); + const auto& file = req.get_file_value("name1"); + // file.filename; + // file.content_type; + auto body = req.body.substr(file.offset, file.length)); +}) +``` + Client Example -------------- +### GET + ```c++ #include #include @@ -89,6 +104,22 @@ int main(void) } ``` +### POST + +```c++ +res = cli.post("/post", "text", "text/plain"); +res = cli.post("/person", "name=john1¬e=coder", "application/x-www-form-urlencoded"); +``` + +### POST with parameters + +```c++ +httplib::Map params; +params["name"] = "john"; +params["note"] = "coder"; +auto res = cli.post("/post", params); +``` + ### With Progress Callback ```cpp