Espresso is a minimalistic and easy-to-use web server written in C++. It is inspired by the popular JavaScript library, Express.js, and aims to bring similar functionality to C++ developers.
I am not a proficient C++ developer and this project has the purpose of being a learning experience for me. I am open to any suggestions and contributions.
- Routing: handle incoming requests using simple and flexible routing.
- Supports GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD, and CONNECT requests.
- Supports URL parameters.
- Middleware: use pre-defined or custom middleware to manipulate requests and responses.
- Static file serving: serve static files from a specified directory.
- ORM (WIP): a Object-Relational Mapping system to interact with a database.
$ git clone https://github.com/micheledallerive/Espresso.git
$ cd espresso
$ mkdir build
$ cd build
$ cmake ..
$ sudo make install
#include <espresso.h>
int main() {
espresso::Server server;
server.router().get("/", [](const espresso::Request &req, espresso::Response &res) {
response.write("Hello, World!");
});
server.listen(3000);
return 0;
}
This will create a new Espresso server that listens on port 3000 and responds to GET requests to the root route (/) with "Hello, World!".
The file can then be built using CMake or simply compiled with:
$ g++ main.cpp -o main -lespresso -std=c++2a
Note: the -lespresso
flag is required to link the Espresso library.
Please refer to the examples
directory for more examples.
Please note, that usage and functionality may be limited and some features that are present in Express may not be present in this project due to it being a learning experience, so it is not intended for production use.