@@ -19,11 +19,11 @@ int main(void)
19
19
20
20
Server svr;
21
21
22
- svr.get ("/hi", [](const Request& req, Response& res) {
22
+ svr.Get ("/hi", [](const Request& req, Response& res) {
23
23
res.set_content("Hello World!", "text/plain");
24
24
});
25
25
26
- svr.get (R"(/numbers/(\d+))", [&](const Request& req, Response& res) {
26
+ svr.Get (R"(/numbers/(\d+))", [&](const Request& req, Response& res) {
27
27
auto numbers = req.matches[1];
28
28
res.set_content(numbers, "text/plain");
29
29
});
@@ -32,13 +32,15 @@ int main(void)
32
32
}
33
33
```
34
34
35
+ `Post`, `Put`, `Delete` and `Options` methods are also supported.
36
+
35
37
### Method Chain
36
38
37
39
```cpp
38
- svr.get ("/get", [](const auto& req, auto& res) {
40
+ svr.Get ("/get", [](const auto& req, auto& res) {
39
41
res.set_content("get", "text/plain");
40
42
})
41
- .post ("/post", [](const auto& req, auto& res) {
43
+ .Post ("/post", [](const auto& req, auto& res) {
42
44
res.set_content(req.body(), "text/plain");
43
45
})
44
46
.listen("localhost", 1234);
@@ -72,7 +74,7 @@ svr.set_error_handler([](const auto& req, auto& res) {
72
74
### 'multipart/form-data' POST data
73
75
74
76
``` cpp
75
- svr.post (" /multipart" , [&](const auto & req, auto & res) {
77
+ svr.Post (" /multipart" , [&](const auto & req, auto & res) {
76
78
auto size = req.files.size();
77
79
auto ret = req.has_file("name1"));
78
80
const auto& file = req.get_file_value("name1");
@@ -95,7 +97,7 @@ int main(void)
95
97
{
96
98
httplib::Client cli("localhost", 1234);
97
99
98
- auto res = cli.get ("/hi");
100
+ auto res = cli.Get ("/hi");
99
101
if (res && res->status == 200) {
100
102
std::cout << res->body << std::endl;
101
103
}
@@ -105,8 +107,8 @@ int main(void)
105
107
### POST
106
108
107
109
```c++
108
- res = cli.post ("/post", "text", "text/plain");
109
- res = cli.post ("/person", "name=john1¬e=coder", "application/x-www-form-urlencoded");
110
+ res = cli.Post ("/post", "text", "text/plain");
111
+ res = cli.Post ("/person", "name=john1¬e=coder", "application/x-www-form-urlencoded");
110
112
```
111
113
112
114
### POST with parameters
@@ -115,7 +117,26 @@ res = cli.post("/person", "name=john1¬e=coder", "application/x-www-form-urlen
115
117
httplib::Map params;
116
118
params[" name" ] = " john" ;
117
119
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" );
119
140
```
120
141
121
142
### Connection Timeout
@@ -130,7 +151,7 @@ httplib::Client client(url, port);
130
151
131
152
// prints: 0 / 000 bytes => 50% complete
132
153
std::shared_ptr<httplib::Response> res =
133
- cli.get ("/", [](uint64_t len, uint64_t total) {
154
+ cli.Get ("/", [](uint64_t len, uint64_t total) {
134
155
printf("%lld / %lld bytes => %d%% complete\n",
135
156
len, total,
136
157
(int)((len/total)*100));
@@ -150,7 +171,7 @@ httplib::Client cli("httpbin.org", 80);
150
171
// 'Range: bytes=1-10'
151
172
httplib::Headers headers = { httplib::make_range_header(1, 10) };
152
173
153
- auto res = cli.get ("/range/32", headers);
174
+ auto res = cli.Get ("/range/32", headers);
154
175
// res->status should be 206.
155
176
// res->body should be "bcdefghijk".
156
177
```
@@ -185,4 +206,4 @@ The server applies gzip compression to the following MIME type contents:
185
206
License
186
207
-------
187
208
188
- MIT license (© 2017 Yuji Hirose)
209
+ MIT license (© 2018 Yuji Hirose)
0 commit comments