Skip to content

Commit 6c5d0b2

Browse files
committed
Fix #57 and #62
1 parent e46cc54 commit 6c5d0b2

File tree

8 files changed

+255
-103
lines changed

8 files changed

+255
-103
lines changed

README.md

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ int main(void)
1919

2020
Server svr;
2121

22-
svr.get("/hi", [](const Request& req, Response& res) {
22+
svr.Get("/hi", [](const Request& req, Response& res) {
2323
res.set_content("Hello World!", "text/plain");
2424
});
2525

26-
svr.get(R"(/numbers/(\d+))", [&](const Request& req, Response& res) {
26+
svr.Get(R"(/numbers/(\d+))", [&](const Request& req, Response& res) {
2727
auto numbers = req.matches[1];
2828
res.set_content(numbers, "text/plain");
2929
});
@@ -32,13 +32,15 @@ int main(void)
3232
}
3333
```
3434
35+
`Post`, `Put`, `Delete` and `Options` methods are also supported.
36+
3537
### Method Chain
3638
3739
```cpp
38-
svr.get("/get", [](const auto& req, auto& res) {
40+
svr.Get("/get", [](const auto& req, auto& res) {
3941
res.set_content("get", "text/plain");
4042
})
41-
.post("/post", [](const auto& req, auto& res) {
43+
.Post("/post", [](const auto& req, auto& res) {
4244
res.set_content(req.body(), "text/plain");
4345
})
4446
.listen("localhost", 1234);
@@ -72,7 +74,7 @@ svr.set_error_handler([](const auto& req, auto& res) {
7274
### 'multipart/form-data' POST data
7375

7476
```cpp
75-
svr.post("/multipart", [&](const auto& req, auto& res) {
77+
svr.Post("/multipart", [&](const auto& req, auto& res) {
7678
auto size = req.files.size();
7779
auto ret = req.has_file("name1"));
7880
const auto& file = req.get_file_value("name1");
@@ -95,7 +97,7 @@ int main(void)
9597
{
9698
httplib::Client cli("localhost", 1234);
9799

98-
auto res = cli.get("/hi");
100+
auto res = cli.Get("/hi");
99101
if (res && res->status == 200) {
100102
std::cout << res->body << std::endl;
101103
}
@@ -105,8 +107,8 @@ int main(void)
105107
### POST
106108
107109
```c++
108-
res = cli.post("/post", "text", "text/plain");
109-
res = cli.post("/person", "name=john1&note=coder", "application/x-www-form-urlencoded");
110+
res = cli.Post("/post", "text", "text/plain");
111+
res = cli.Post("/person", "name=john1&note=coder", "application/x-www-form-urlencoded");
110112
```
111113

112114
### POST with parameters
@@ -115,7 +117,26 @@ res = cli.post("/person", "name=john1&note=coder", "application/x-www-form-urlen
115117
httplib::Map params;
116118
params["name"] = "john";
117119
params["note"] = "coder";
118-
auto res = cli.post("/post", params);
120+
auto res = cli.Post("/post", params);
121+
```
122+
123+
### PUT
124+
125+
```c++
126+
res = cli.Post("/resource/foo", "text", "text/plain");
127+
```
128+
129+
### DELETE
130+
131+
```c++
132+
res = cli.Delete("/resource/foo");
133+
```
134+
135+
### OPTIONS
136+
137+
```c++
138+
res = cli.Options("*");
139+
res = cli.Options("/resource/foo");
119140
```
120141

121142
### Connection Timeout
@@ -130,7 +151,7 @@ httplib::Client client(url, port);
130151
131152
// prints: 0 / 000 bytes => 50% complete
132153
std::shared_ptr<httplib::Response> res =
133-
cli.get("/", [](uint64_t len, uint64_t total) {
154+
cli.Get("/", [](uint64_t len, uint64_t total) {
134155
printf("%lld / %lld bytes => %d%% complete\n",
135156
len, total,
136157
(int)((len/total)*100));
@@ -150,7 +171,7 @@ httplib::Client cli("httpbin.org", 80);
150171
// 'Range: bytes=1-10'
151172
httplib::Headers headers = { httplib::make_range_header(1, 10) };
152173

153-
auto res = cli.get("/range/32", headers);
174+
auto res = cli.Get("/range/32", headers);
154175
// res->status should be 206.
155176
// res->body should be "bcdefghijk".
156177
```
@@ -185,4 +206,4 @@ The server applies gzip compression to the following MIME type contents:
185206
License
186207
-------
187208

188-
MIT license (© 2017 Yuji Hirose)
209+
MIT license (© 2018 Yuji Hirose)

example/benchmark.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ int main(void) {
2525

2626
for (int i = 0; i < 3; i++) {
2727
StopWatch sw(to_string(i).c_str());
28-
auto res = cli.post("/post", body, "application/octet-stream");
28+
auto res = cli.Post("/post", body, "application/octet-stream");
2929
assert(res->status == 200);
3030
}
3131

example/client.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int main(void)
1818
httplib::Client cli("localhost", 8080);
1919
#endif
2020

21-
auto res = cli.get("/hi");
21+
auto res = cli.Get("/hi");
2222
if (res) {
2323
cout << res->status << endl;
2424
cout << res->get_header_value("Content-Type") << endl;

example/hello.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ int main(void)
1212
{
1313
Server svr;
1414

15-
svr.get("/hi", [](const auto& /*req*/, auto& res) {
15+
svr.Get("/hi", [](const auto& /*req*/, auto& res) {
1616
res.set_content("Hello World!", "text/plain");
1717
});
1818

example/server.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,25 +81,25 @@ int main(void)
8181
return -1;
8282
}
8383

84-
svr.get("/", [=](const auto& /*req*/, auto& res) {
84+
svr.Get("/", [=](const auto& /*req*/, auto& res) {
8585
res.set_redirect("/hi");
8686
});
8787

88-
svr.get("/hi", [](const auto& /*req*/, auto& res) {
88+
svr.Get("/hi", [](const auto& /*req*/, auto& res) {
8989
res.set_content("Hello World!\n", "text/plain");
9090
});
9191

92-
svr.get("/slow", [](const auto& /*req*/, auto& res) {
92+
svr.Get("/slow", [](const auto& /*req*/, auto& res) {
9393
using namespace std::chrono_literals;
9494
std::this_thread::sleep_for(2s);
9595
res.set_content("Slow...\n", "text/plain");
9696
});
9797

98-
svr.get("/dump", [](const auto& req, auto& res) {
98+
svr.Get("/dump", [](const auto& req, auto& res) {
9999
res.set_content(dump_headers(req.headers), "text/plain");
100100
});
101101

102-
svr.get("/stop", [&](const auto& /*req*/, auto& /*res*/) {
102+
svr.Get("/stop", [&](const auto& /*req*/, auto& /*res*/) {
103103
svr.stop();
104104
});
105105

example/simplesvr.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ int main(int argc, const char** argv)
107107
Server svr(version);
108108
#endif
109109

110-
svr.post("/multipart", [](const auto& req, auto& res) {
110+
svr.Post("/multipart", [](const auto& req, auto& res) {
111111
auto body =
112112
dump_headers(req.headers) +
113113
dump_multipart_files(req.files);

0 commit comments

Comments
 (0)