### Run a basic RESTinio server Source: https://github.com/stiffstream/restinio/blob/master/dev/mainpage.dox A minimal example demonstrating how to start a RESTinio server on the main thread that responds to all requests with a 'Hello, World!' message. ```cpp #include #include int main() { restinio::run( restinio::on_this_thread() .port(8080) .address("localhost") .request_handler([](auto req) { return req->create_response().set_body("Hello, World!").done(); })); return 0; } ``` -------------------------------- ### Run a Basic HTTP Server Source: https://github.com/stiffstream/restinio/blob/master/README.md Starts a simple HTTP server on the main thread that responds to all requests with a 'Hello, World!' message. ```C++ #include int main() { restinio::run( restinio::on_this_thread() .port(8080) .address("localhost") .request_handler([](auto req) { return req->create_response().set_body("Hello, World!").done(); })); return 0; } ``` -------------------------------- ### Complex Route Examples Source: https://github.com/stiffstream/restinio/blob/master/dev/test/router/express_router_bench/many_routes.txt Examples of complex and deeply nested routes. ```APIDOC ## GET /some/:id(\\d+)/long/:route/path/(\\d\\w[aeiouy][b]?[aeiouy]) ### Description An example of a complex route with multiple path parameters and regex constraints. ### Method GET ### Endpoint /some/:id(\\d+)/long/:route/path/(\\d\\w[aeiouy][b]?[aeiouy]) ## GET /:some(\\w\\d*)/:id(\\d+)/long/:route/path/(\\d\\w[aeiouy][b]?[aeiouy]) ### Description Another example of a complex route with a leading parameter. ### Method GET ### Endpoint /:some(\\w\\d*)/:id(\\d+)/long/:route/path/(\\d\\w[aeiouy][b]?[aeiouy]) ## GET /:some/:id(\\d+)/long/:route/path/(\\d\\w[aeiouy][b]?[aeiouy]) ### Description Example of a route with a named parameter and a regex-constrained parameter. ### Method GET ### Endpoint /:some/:id(\\d+)/long/:route/path/(\\d\\w[aeiouy][b]?[aeiouy]) ## GET /another/:xxx(\\w):yyy(\\d):zzz([abcd][xyz])/:id(\\d+)/long/:route/path/(\\d\\w[aeiouy][b]?[aeiouy]) ### Description Demonstrates a route with multiple consecutive regex-constrained parameters. ### Method GET ### Endpoint /another/:xxx(\\w):yyy(\\d):zzz([abcd][xyz])/:id(\\d+)/long/:route/path/(\\d\\w[aeiouy][b]?[aeiouy]) ## GET /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description A very long, static route. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /:a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a single leading parameter. ### Method GET ### Endpoint /:a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /a/:b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the second segment. ### Method GET ### Endpoint /a/:b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /a/b/:c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the third segment. ### Method GET ### Endpoint /a/b/:c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /a/b/c/:d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the fourth segment. ### Method GET ### Endpoint /a/b/c/:d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /a/b/c/d/:e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the fifth segment. ### Method GET ### Endpoint /a/b/c/d/:e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /a/b/c/d/e/:f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the sixth segment. ### Method GET ### Endpoint /a/b/c/d/e/:f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /a/b/c/d/e/f/:g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the seventh segment. ### Method GET ### Endpoint /a/b/c/d/e/f/:g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /a/b/c/d/e/f/g/:h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the eighth segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/:h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /a/b/c/d/e/f/g/h/:i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the ninth segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/:i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /a/b/c/d/e/f/g/h/i/:j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the tenth segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/:j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /a/b/c/d/e/f/g/h/i/j/:k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the eleventh segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/:k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /a/b/c/d/e/f/g/h/i/j/k/:l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the twelfth segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/:l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /a/b/c/d/e/f/g/h/i/j/k/l/:m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the thirteenth segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/l/:m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /a/b/c/d/e/f/g/h/i/j/k/l/m/:n/o/p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the fourteenth segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/l/m/:n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /a/b/c/d/e/f/g/h/i/j/k/l/m/n/:o/p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the fifteenth segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/l/m/n/:o/p/q/r/s/t/u/v/w/x/y/z ## GET /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/:p/q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the sixteenth segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/:p/q/r/s/t/u/v/w/x/y/z ## GET /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/:q/r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the seventeenth segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/:q/r/s/t/u/v/w/x/y/z ## GET /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/:r/s/t/u/v/w/x/y/z ### Description A long route with a parameter in the eighteenth segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/:r/s/t/u/v/w/x/y/z ## GET /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/:s/t/u/v/w/x/y/z ### Description A long route with a parameter in the nineteenth segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/:s/t/u/v/w/x/y/z ## GET /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/:t/u/v/w/x/y/z ### Description A long route with a parameter in the twentieth segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/:t/u/v/w/x/y/z ## GET /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/:u/v/w/x/y/z ### Description A long route with a parameter in the twenty-first segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/:u/v/w/x/y/z ## GET /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/:v/w/x/y/z ### Description A long route with a parameter in the twenty-second segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/:v/w/x/y/z ## GET /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/:w/x/y/z ### Description A long route with a parameter in the twenty-third segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/:w/x/y/z ## GET /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/:x/y/z ### Description A long route with a parameter in the twenty-fourth segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/:x/y/z ## GET /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/:y/z ### Description A long route with a parameter in the twenty-fifth segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/:y/z ## GET /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/:z ### Description A long route with a parameter in the twenty-sixth segment. ### Method GET ### Endpoint /a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/:z ## GET /:a(\\d+)/:b(\\d+)/:c(\\d+)/:d(\\d+)/:e(\\d+)/:f(\\d+)/:g(\\d+)/:h(\\d+)/:i(\\d+)/:j(\\d+)/:k(\\d+)/:l(\\d+)/:m(\\d+)/:n(\\d+)/:o(\\d+)/:p(\\d+)/:q(\\d+)/:r(\\d+)/:s(\\d+)/:t(\\d+)/:u(\\d+)/:v(\\d+)/:w(\\d+)/:x(\\d+)/:y(\\d+)/:z(\\d+) ### Description An example of a route with 26 consecutive numeric parameters. ### Method GET ### Endpoint /:a(\\d+)/:b(\\d+)/:c(\\d+)/:d(\\d+)/:e(\\d+)/:f(\\d+)/:g(\\d+)/:h(\\d+)/:i(\\d+)/:j(\\d+)/:k(\\d+)/:l(\\d+)/:m(\\d+)/:n(\\d+)/:o(\\d+)/:p(\\d+)/:q(\\d+)/:r(\\d+)/:s(\\d+)/:t(\\d+)/:u(\\d+)/:v(\\d+)/:w(\\d+)/:x(\\d+)/:y(\\d+)/:z(\\d+) ## GET /:a/:b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description Route with multiple leading parameters. ### Method GET ### Endpoint /:a/:b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## POST /:a/:b/:c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description POST request for a route with multiple leading parameters. ### Method POST ### Endpoint /:a/:b/:c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /:a/:b/:c/:d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description Route with multiple leading parameters, each potentially a segment. ### Method GET ### Endpoint /:a/:b/:c/:d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## POST /:a/:b/:c/:d/:e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description POST request for a route with multiple leading parameters. ### Method POST ### Endpoint /:a/:b/:c/:d/:e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /:a/:b/:c/:d/:e/:f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description Route with more leading parameters. ### Method GET ### Endpoint /:a/:b/:c/:d/:e/:f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## POST /:a/:b/:c/:d/:e/:f/:g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description POST request for a route with more leading parameters. ### Method POST ### Endpoint /:a/:b/:c/:d/:e/:f/:g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /:a/:b/:c/:d/:e/:f/:g/:h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description Route with even more leading parameters. ### Method GET ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## POST /:a/:b/:c/:d/:e/:f/:g/:h/:i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description POST request for a route with even more leading parameters. ### Method POST ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description Route with a significant number of leading parameters. ### Method GET ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## POST /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description POST request for a route with a significant number of leading parameters. ### Method POST ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description Route with many leading parameters. ### Method GET ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/m/n/o/p/q/r/s/t/u/v/w/x/y/z ## POST /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/n/o/p/q/r/s/t/u/v/w/x/y/z ### Description POST request for a route with many leading parameters. ### Method POST ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/n/o/p/q/r/s/t/u/v/w/x/y/z ## GET /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/o/p/q/r/s/t/u/v/w/x/y/z ### Description Route with a large number of leading parameters. ### Method GET ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/o/p/q/r/s/t/u/v/w/x/y/z ## POST /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/p/q/r/s/t/u/v/w/x/y/z ### Description POST request for a route with a large number of leading parameters. ### Method POST ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/p/q/r/s/t/u/v/w/x/y/z ## GET /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/q/r/s/t/u/v/w/x/y/z ### Description Route with a very large number of leading parameters. ### Method GET ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/q/r/s/t/u/v/w/x/y/z ## POST /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/r/s/t/u/v/w/x/y/z ### Description POST request for a route with a very large number of leading parameters. ### Method POST ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/r/s/t/u/v/w/x/y/z ## GET /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/s/t/u/v/w/x/y/z ### Description Route with numerous leading parameters. ### Method GET ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/s/t/u/v/w/x/y/z ## POST /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/t/u/v/w/x/y/z ### Description POST request for a route with numerous leading parameters. ### Method POST ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/t/u/v/w/x/y/z ## GET /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/:t/u/v/w/x/y/z ### Description Route with a vast number of leading parameters. ### Method GET ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/:t/u/v/w/x/y/z ## POST /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/:t/:u/v/w/x/y/z ### Description POST request for a route with a vast number of leading parameters. ### Method POST ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/:t/:u/v/w/x/y/z ## GET /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/:t/:u/:v/w/x/y/z ### Description Route with an extreme number of leading parameters. ### Method GET ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/:t/:u/:v/w/x/y/z ## POST /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/:t/:u/:v/:w/x/y/z ### Description POST request for a route with an extreme number of leading parameters. ### Method POST ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/:t/:u/:v/:w/x/y/z ## POST /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/:t/:u/:v/:w/:x/y/z ### Description POST request with a very long sequence of parameters. ### Method POST ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/:t/:u/:v/:w/:x/y/z ## GET /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/:t/:u/:v/:w/:x/:y/z ### Description GET request with a very long sequence of parameters. ### Method GET ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/:t/:u/:v/:w/:x/:y/z ## POST /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/:t/:u/:v/:w/:x/:y/:z ### Description POST request with a very long sequence of parameters, ending in z. ### Method POST ### Endpoint /:a/:b/:c/:d/:e/:f/:g/:h/:i/:j/:k/:l/:m/:n/:o/:p/:q/:r/:s/:t/:u/:v/:w/:x/:y/:z ``` -------------------------------- ### Launch Asynchronous Server with run_async Source: https://context7.com/stiffstream/restinio/llms.txt Starts a non-blocking server in the background that automatically stops when the returned handle goes out of scope. ```cpp #include #include #include int main() { auto server = restinio::run_async( restinio::own_io_context(), restinio::server_settings_t{} .address("127.0.0.1") .port(8080) .request_handler([](auto req) { return req->create_response() .set_body("Async server running!") .done(); }), 16 // thread pool size ); // Server is running in background std::this_thread::sleep_for(std::chrono::minutes(5)); // Server auto-stops when 'server' goes out of scope // Or manually: server->stop(); server->wait(); return 0; } ``` -------------------------------- ### Simple Routes API Source: https://github.com/stiffstream/restinio/blob/master/dev/test/router/express_router_bench/many_routes.txt Endpoints for simple route examples. ```APIDOC ## GET /simple/routes ### Description Retrieves a list of simple routes. ### Method GET ### Endpoint /simple/routes ## GET /simple/routes/(\\d+) ### Description Retrieves a simple route with a numeric parameter. ### Method GET ### Endpoint /simple/routes/(\\d+) ## GET /simple/routes/(\\w+) ### Description Retrieves a simple route with a word parameter. ### Method GET ### Endpoint /simple/routes/(\\w+) ``` -------------------------------- ### Launch Restinio TLS Server Source: https://github.com/stiffstream/restinio/blob/master/dev/sample/tls_inspector/certs/README.md Starts the Restinio TLS server. Ensure the provided path points to the directory containing the CA and server certificates. ```sh ./target/release/sample.tls_inspector sample/tls_inspector/certs ``` -------------------------------- ### Basic GET Endpoints Source: https://github.com/stiffstream/restinio/blob/master/dev/test/router/express_router_bench/simple.txt This section covers the basic GET endpoints for various string patterns. ```APIDOC ## GET /abcd ### Description Retrieves resources associated with the 'abcd' pattern. ### Method GET ### Endpoint /abcd ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the 'abcd' resource. #### Response Example None ``` ```APIDOC ## GET /abcd0123456 ### Description Retrieves resources associated with the 'abcd' pattern followed by a numeric string. ### Method GET ### Endpoint /abcd0123456 ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the 'abcd0123456' resource. #### Response Example None ``` ```APIDOC ## GET /bcda ### Description Retrieves resources associated with the 'bcda' pattern. ### Method GET ### Endpoint /bcda ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the 'bcda' resource. #### Response Example None ``` ```APIDOC ## GET /bcda0123456 ### Description Retrieves resources associated with the 'bcda' pattern followed by a numeric string. ### Method GET ### Endpoint /bcda0123456 ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the 'bcda0123456' resource. #### Response Example None ``` ```APIDOC ## GET /cdab ### Description Retrieves resources associated with the 'cdab' pattern. ### Method GET ### Endpoint /cdab ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the 'cdab' resource. #### Response Example None ``` ```APIDOC ## GET /cdab0123456 ### Description Retrieves resources associated with the 'cdab' pattern followed by a numeric string. ### Method GET ### Endpoint /cdab0123456 ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the 'cdab0123456' resource. #### Response Example None ``` ```APIDOC ## GET /dabc ### Description Retrieves resources associated with the 'dabc' pattern. ### Method GET ### Endpoint /dabc ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the 'dabc' resource. #### Response Example None ``` ```APIDOC ## GET /dabc0123456 ### Description Retrieves resources associated with the 'dabc' pattern followed by a numeric string. ### Method GET ### Endpoint /dabc0123456 ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the 'dabc0123456' resource. #### Response Example None ``` -------------------------------- ### Parse Query String Parameters in RESTinio Source: https://context7.com/stiffstream/restinio/llms.txt Demonstrates how to parse and access URL query string parameters using `parse_query()`. Supports different parsing modes and provides methods to get parameters with or without default values. ```cpp #include restinio::request_handling_status_t handler(const restinio::request_handle_t& req) { if (restinio::http_method_get() == req->header().method()) { // Parse query string: /search?q=hello&page=1&limit=10 const auto qp = restinio::parse_query(req->header().query()); std::string response = "Query parameters:\n"; // Check if parameter exists and get value if (qp.has("q")) { response += "q = " + std::string(qp["q"]) + "\n"; } // Get with default value int page = restinio::value_or(qp, "page", 1); int limit = restinio::value_or(qp, "limit", 20); response += "page = " + std::to_string(page) + "\n"; response += "limit = " + std::to_string(limit) + "\n"; // Iterate all parameters for (const auto& p : qp) { response += std::string(p.first) + " => " + std::string(p.second) + "\n"; } return req->create_response() .append_header(restinio::http_field::content_type, "text/plain") .set_body(response) .done(); } return restinio::request_rejected(); } int main() { restinio::run( restinio::on_thread_pool(4) .port(8080) .address("localhost") .request_handler(handler)); return 0; } ``` -------------------------------- ### Configure Sample Build with CMake Source: https://github.com/stiffstream/restinio/blob/master/dev/sample/hello_world_sendfile/CMakeLists.txt This CMake script configures the 'hello_world_sendfile' sample. It includes a common sample configuration and links the sample target against the restinio_helpers::cmd_line_args library. ```cmake set(SAMPLE sample.hello_world_sendfile) include(${CMAKE_SOURCE_DIR}/cmake/sample.cmake) target_link_libraries(${SAMPLE} PRIVATE restinio_helpers::cmd_line_args) ``` -------------------------------- ### GET Endpoints with Numeric Prefixes Source: https://github.com/stiffstream/restinio/blob/master/dev/test/router/express_router_bench/simple.txt This section covers GET endpoints with numeric prefixes. ```APIDOC ## GET /1abcd ### Description Retrieves resources associated with the pattern '1abcd'. ### Method GET ### Endpoint /1abcd ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the '1abcd' resource. #### Response Example None ``` ```APIDOC ## GET /2bcda ### Description Retrieves resources associated with the pattern '2bcda'. ### Method GET ### Endpoint /2bcda ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the '2bcda' resource. #### Response Example None ``` ```APIDOC ## GET /3cdab ### Description Retrieves resources associated with the pattern '3cdab'. ### Method GET ### Endpoint /3cdab ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the '3cdab' resource. #### Response Example None ``` ```APIDOC ## GET /4dabc ### Description Retrieves resources associated with the pattern '4dabc'. ### Method GET ### Endpoint /4dabc ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the '4dabc' resource. #### Response Example None ``` -------------------------------- ### GET Endpoints with Suffixes Source: https://github.com/stiffstream/restinio/blob/master/dev/test/router/express_router_bench/simple.txt This section covers GET endpoints with specific string suffixes. ```APIDOC ## GET /abcd1 ### Description Retrieves resources associated with the pattern 'abcd1'. ### Method GET ### Endpoint /abcd1 ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the 'abcd1' resource. #### Response Example None ``` ```APIDOC ## GET /bcda2 ### Description Retrieves resources associated with the pattern 'bcda2'. ### Method GET ### Endpoint /bcda2 ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the 'bcda2' resource. #### Response Example None ``` ```APIDOC ## GET /cdab3 ### Description Retrieves resources associated with the pattern 'cdab3'. ### Method GET ### Endpoint /cdab3 ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the 'cdab3' resource. #### Response Example None ``` ```APIDOC ## GET /dabc4 ### Description Retrieves resources associated with the pattern 'dabc4'. ### Method GET ### Endpoint /dabc4 ### Parameters None ### Request Example None ### Response #### Success Response (200) Details of the 'dabc4' resource. #### Response Example None ``` -------------------------------- ### Configure Restinio Sample with CMake Source: https://github.com/stiffstream/restinio/blob/master/dev/sample/file_upload/CMakeLists.txt Sets up the sample target and links necessary command line argument helpers. ```cmake set(SAMPLE sample.file_upload) include(${CMAKE_SOURCE_DIR}/cmake/sample.cmake) target_link_libraries(${SAMPLE} PRIVATE restinio_helpers::cmd_line_args) ``` -------------------------------- ### Configure RESTinio Sample with OpenSSL Source: https://github.com/stiffstream/restinio/blob/master/dev/sample/hello_world_https/CMakeLists.txt Sets up the sample target and links the required OpenSSL include directories and libraries. ```cmake set(SAMPLE sample.hello_world_https) include(${CMAKE_SOURCE_DIR}/cmake/sample.cmake) TARGET_INCLUDE_DIRECTORIES(${SAMPLE} PRIVATE ${OPENSSL_INCLUDE_DIR}) TARGET_LINK_LIBRARIES(${SAMPLE} PRIVATE ${OPENSSL_LIBRARIES}) ``` -------------------------------- ### Parameterized GET Endpoint Source: https://github.com/stiffstream/restinio/blob/master/dev/test/router/express_router_bench/simple.txt This section details a GET endpoint that accepts a numeric ID as a path parameter. ```APIDOC ## GET /XXX/:id ### Description Retrieves resources associated with the 'XXX' pattern, identified by a numeric ID. ### Method GET ### Endpoint /XXX/:id ### Parameters #### Path Parameters - **id** (integer) - Required - The numeric identifier for the resource. ### Request Example None ### Response #### Success Response (200) Details of the resource identified by the provided ID. #### Response Example None ``` -------------------------------- ### Configure RESTinio Async Chained Handlers Sample Source: https://github.com/stiffstream/restinio/blob/master/dev/sample/async_chained_handlers/CMakeLists.txt Sets up the build target and links required dependencies for the async_chained_handlers sample. ```cmake set(SAMPLE sample.async_chained_handlers) include(${CMAKE_SOURCE_DIR}/cmake/sample.cmake) if (RESTINIO_DEP_SOBJECTIZER STREQUAL "system") target_compile_definitions(${SAMPLE} PRIVATE SO_5_STATIC_LIB) endif() target_link_libraries(${SAMPLE} PRIVATE ${RESTINIO_SOBJECTIZER_LIB_LINK_NAME}) ``` -------------------------------- ### Manage Project Subdirectories Source: https://github.com/stiffstream/restinio/blob/master/dev/CMakeLists.txt Handles the inclusion of the main library, tests, samples, and benchmarks based on build options. ```cmake message("========================================") message(STATUS "Defining restinio target...") add_subdirectory(restinio) message("========================================") if (RESTINIO_TEST) if (RESTINIO_DEP_CATCH2 STREQUAL "find") find_package(Catch2 REQUIRED) elseif (RESTINIO_DEP_CATCH2 STREQUAL "local") message("========================================") message(STATUS "Add subdirectory catch2") set(CATCH_INSTALL_DOCS OFF) set(CATCH_INSTALL_EXTRAS OFF) set(CATCH_DEVELOPMENT_BUILD OFF) set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) add_subdirectory(catch2) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/catch2/extras) message("========================================") endif () include(Catch) enable_testing() add_subdirectory(test) endif () if (RESTINIO_SAMPLE) include_directories("${CMAKE_SOURCE_DIR}/clara") add_subdirectory(sample) endif () if (RESTINIO_BENCHMARK) include_directories("${CMAKE_SOURCE_DIR}/clara") add_subdirectory(benches) endif () ``` -------------------------------- ### Server Configuration and Timeouts Source: https://context7.com/stiffstream/restinio/llms.txt Configure server behavior including timeouts, buffer sizes, and connection limits. Use chrono durations for time-related settings. ```cpp #include int main() { using namespace std::chrono; using traits_t = restinio::default_traits_t; restinio::run( restinio::on_thread_pool(8) // Network settings .port(8080) .address("0.0.0.0") // Timeouts .read_next_http_message_timelimit(30s) // Read timeout .write_http_response_timelimit(60s) // Write timeout .handle_request_timeout(120s) // Handler timeout .max_pipelined_requests(4) // HTTP pipelining // Connection settings .concurrent_accepts_count(8) // Parallel accepts // Buffer configuration .buffer_size(4096) // Cleanup function called on shutdown .cleanup_func([]() { std::cout << "Server shutting down..." << std::endl; }) // Request handler .request_handler([](auto req) { return req->create_response() .set_body("Configured server!") .done(); })); return 0; } ``` -------------------------------- ### Add a new book via POST Source: https://github.com/stiffstream/restinio/blob/master/dev/sample/easy_parser_router/curl_examples.txt Sends a POST request with a text file payload to create a new book entry. ```bash curl http://localhost:8080/ -X POST -H "Content-type: text/plain" -v -d @sample/easy_parser_router/new_book_1.txt ``` -------------------------------- ### Serve Static Files with Sendfile Source: https://context7.com/stiffstream/restinio/llms.txt Efficiently serve files using OS-level sendfile/TransmitFile operations. Supports partial content (Range requests) and file metadata. Ensure the root directory exists and is accessible. ```cpp #include using router_t = restinio::router::express_router_t<>; auto create_file_server(const std::string& root_dir) { auto router = std::make_unique(); router->http_get(R"(/:path(.*)\.:ext(.*))", [root_dir](auto req, auto params) { auto path = req->header().path(); // Security check if (path.find("..") != std::string::npos) { return req->create_response(restinio::status_forbidden()) .set_body("Access denied") .done(); } std::string file_path = root_dir + std::string(path); try { // Create sendfile object auto sf = restinio::sendfile(file_path); // Get file metadata for headers auto modified = restinio::make_date_field_value( sf.meta().last_modified_at()); return req->create_response() .append_header(restinio::http_field::server, "RESTinio") .append_header_date_field() .append_header(restinio::http_field::last_modified, modified) .append_header(restinio::http_field::content_type, "text/plain") .set_body(std::move(sf)) .done(); } catch (const std::exception&) { return req->create_response(restinio::status_not_found()) .set_body("File not found") .done(); } }); return router; } int main() { using traits_t = restinio::traits_t< restinio::asio_timer_manager_t, restinio::null_logger_t, router_t>; restinio::run( restinio::on_thread_pool(4) .port(8080) .address("localhost") .request_handler(create_file_server("./public"))); return 0; } ``` -------------------------------- ### Implement Express-style Routing Source: https://github.com/stiffstream/restinio/blob/master/README.md Demonstrates using an express_router_t to handle specific URL patterns with parameters and query string parsing. ```C++ #include using namespace restinio; template std::ostream & operator<<(std::ostream & to, const optional_t & v) { if(v) to << *v; return to; } int main() { // Create express router for our service. auto router = std::make_unique>(); router->http_get( R"(/data/meter/:meter_id(\d+))", [](auto req, auto params) { const auto qp = parse_query(req->header().query()); return req->create_response() .set_body( fmt::format("meter_id={} (year={}/mon={}/day={})", cast_to(params["meter_id"]), opt_value(qp, "year"), opt_value(qp, "mon"), opt_value(qp, "day"))) .done(); }); router->non_matched_request_handler( [](auto req){ return req->create_response(restinio::status_not_found()).connection_close().done(); }); // Launching a server with custom traits. struct my_server_traits : public default_single_thread_traits_t { using request_handler_t = restinio::router::express_router_t<>; }; restinio::run( restinio::on_this_thread() .address("localhost") .request_handler(std::move(router))); return 0; } ```