Skip to content

Commit 8bda27b

Browse files
Add module examples
1 parent 41eb63f commit 8bda27b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,38 @@ Build C++ Modules
12581258

12591259
If using CMake, it is possible to build this as a C++20 module using the `HTTPLIB_BUILD_MODULES` option (which requires `HTTPLIB_COMPILE` to be enabled).
12601260

1261+
#### Server (Multi-threaded)
1262+
```cpp
1263+
import httplib;
1264+
1265+
using httplib::Request;
1266+
using httplib::Response;
1267+
using httplib::SSLServer;
1268+
1269+
SSLServer svr;
1270+
1271+
svr.Get("/hi", []([[maybe_unused]] const Request&, Response& res) -> void {
1272+
res.set_content("Hello World!", "text/plain");
1273+
});
1274+
1275+
svr.listen("0.0.0.0", 8080);
1276+
```
1277+
1278+
#### Client
1279+
```cpp
1280+
import httplib;
1281+
1282+
using httplib::Client;
1283+
using httplib::Result
1284+
1285+
Client cli("https://yhirose.github.io");
1286+
1287+
if (Result res = cli.Get("/hi")) {
1288+
res->status;
1289+
res->body;
1290+
}
1291+
```
1292+
12611293
Dockerfile for Static HTTP Server
12621294
---------------------------------
12631295

0 commit comments

Comments
 (0)