Fast, unopinionated, minimalist web framework for C++ Perfect for building REST APIs
ExpressCpp aims to be for C++ the same as express for Node.JS including its ecosystem of middlewares and extensions.
Express and Node.JS:
const express = require('express');
const app = express();
app.get('/', (req, res) => res.send('Hello World!'));
const port = 3000;
app.listen(port, () => console.log(`Listening on port ${port}!`));
ExpressCpp:
#include "expresscpp/expresscpp.hpp"
int main() {
auto expresscpp = std::make_shared<expresscpp::ExpressCpp>();
expresscpp->Get("/", [](auto /*req*/, auto res) { res->Send("hello world!"); });
constexpr uint16_t port = 3000u;
expresscpp->Listen(port,[=](auto /*ec*/) { std::cout << "Listening on port " << port << std::endl; }).Run();
return 0;
}
conan remote add expresscpp https://api.bintray.com/conan/expresscpp/expresscpp/
add this to you conan file:
expresscpp/0.11.0@expresscpp/testing
this to your cmake:
find_package(expresscpp)
# ...
target_link_libraries(my_target PRIVATE expresscpp::expresscpp)
add_subdirectory(thirdparty/expresscpp)
# ...
target_link_libraries(my_target PRIVATE expresscpp::expresscpp)
git clone https://gitlab.com/expresscpp/expresscpp.git
cd expresscpp
mkdir build
cd build
cmake ..
make -j
sudo make install
find_package(expresscpp)
# ...
target_link_libraries(my_target PRIVATE expresscpp::expresscpp)
- boost[asio, beast, uuid]
- nlohmann/json
- libfmt
- gtest (optional)
sudo apt install -y cmake gcc-9 g++-9 python3-pip
# conan for dependency management
sudo pip3 install conan --upgrade
mkdir -p build
cd build
cmake .. -DEXPRESSCPP_USE_CONAN_DEPENDENCIES=ON
cmake --build . -j
sudo apt install -y cmake gcc-9 g++-9
# get debian dependencies
sudo apt install -y libboost-all-dev nlohmann-json3-dev libfmt-dev libgtest-dev
mkdir -p build
cd build
cmake ..
cmake --build . -j
name | file |
---|---|
url query params | ./example/query_params.cpp |
url params | ./example/url_params.cpp |
auth-like middleware | ./example/middleware_auth_like.cpp |
log-like middleware | ./example/middleware_logger_like.cpp |
error handler | ./example/error_handler.cpp |
variadic middlewares | ./example/multiple_handlers.cpp |
subrouting | ./example/router.cpp |
name | file |
---|---|
static file provider | ./example/serve_static.cpp |
favicon provider(embedded) | ./example/favicon.cpp |
- expresscpp-logger -> TODO
- expresscpp-grpc-proxy -> TODO
- expresscpp-reverse-proxy -> TODO
- expresscpp-basic-auth -> TODO
name | repo |
---|---|
BeastHttp | https://github.com/0xdead4ead/BeastHttp/ |
crow (unmaintained) | https://github.com/ipkn/crow |
Simple-Web-Server | https://gitlab.com/eidheim/Simple-Web-Server |
restinio | https://github.com/stiffstream/restinio |
served | https://github.com/meltwater/served |