@@ -7,10 +7,36 @@ A C++11 single-file header-only cross platform HTTP/HTTPS library.
77
88It's extremely easy to setup. Just include ** httplib.h** file in your code!
99
10- NOTE: This is a 'blocking' HTTP client/server library. If you are looking for a 'non-blocking' library, this is not the one that you want.
10+ NOTE: This is a 'blocking' HTTP library. If you are looking for a 'non-blocking' library, this is not the one that you want.
1111
12- Server Example
13- --------------
12+ Simple examples
13+ ---------------
14+
15+ ### [ Server] ( https://repl.it/@yhirose/cpp-httplib-server#main.cpp ) :
16+
17+ ``` c++
18+ httplib::Server svr;
19+
20+ svr.Get(" /hi" , [](const httplib::Request &, httplib::Response &res) {
21+ res.set_content("Hello World!", "text/plain");
22+ });
23+
24+ svr.listen(" 0.0.0.0" , 8080 );
25+ ```
26+
27+ ### [ Client] ( https://repl.it/@yhirose/cpp-httplib-client#main.cpp ) :
28+
29+ ``` c++
30+ httplib::Client cli ("http://cpp-httplib-server.yhirose.repl.co ");
31+
32+ auto res = cli.Get("/hi");
33+
34+ res->status; // 200
35+ res->body; // "Hello World!"
36+ ```
37+
38+ Server
39+ ------
1440
1541```c++
1642#include <httplib.h>
@@ -297,8 +323,8 @@ svr.new_task_queue = [] {
297323};
298324```
299325
300- Client Example
301- --------------
326+ Client
327+ ------
302328
303329```c++
304330#include <httplib.h>
@@ -566,9 +592,9 @@ NOTE: cpp-httplib currently supports only version 1.1.1.
566592``` c++
567593#define CPPHTTPLIB_OPENSSL_SUPPORT
568594
569- SSLServer svr ("./cert.pem", "./key.pem");
595+ httplib:: SSLServer svr ("./cert.pem", "./key.pem");
570596
571- SSLClient cli("localhost", 8080);
597+ httplib:: SSLClient cli("localhost", 1234); // or ` httplib::Client cli("https://localhost:1234"); `
572598cli.set_ca_cert_path("./ca-bundle.crt");
573599cli.enable_server_certificate_verification(true);
574600```
0 commit comments