Pistache is a web framework written in Modern C++ that focuses on performance and provides an elegant and asynchronous API.
If you're on Ubuntu and want to skip the compilation process you can add the official PPA providing nightly builds:
Otherwise, here's how to build and install the latest release:
Also, Pistache does not support Windows yet, but should work fine under WSL.
First, let’s start by including the right header.
Requests received by Pistache are handled with an
Let’s start by defining a simple
Handlers must inherit the
Http::Handler class and at least define the
onRequest member function. They must also define a
clone() member function. Simple handlers can use the special
HTTP_PROTOTYPE macro, passing in the name of the class. The macro will take care of defining the
clone() member function for you.
After defining the handler, the server can now be started:
For simplicity, you can also use the special
listenAndServe function that will automatically create an endpoint and instantiate your handler:
And that’s it, now you can fire up your favorite curl request and observe the final result:
Complete code for this example can be found on GitHub: examples/hello_server.cc