A modern, FastAPI-inspired web framework for C++17 and above, built on top of cpp-httplib and nlohmann/json.
Write clean, type-safe, and declarative APIs in C++ with path params, request body models, and automatic JSON serialization.
- FastAPI-style routing
- Path parameters
- Request body models with validation
- Automatic JSON serialization
- Simple response handling
- Centralized server runner
- Extensible validation layer
- Supports all HTTP methods: GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD
git clone https://github.com/YashArote/fastapi-cpp.git
cd fastapi-cppYou can build the project in Debug or Release mode using CMake. This creates the library.
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config ReleaseYou can install it system-wide (e.g., /usr/local on Linux/macOS or C:/Program Files on Windows).
Cross-Platform Installation:
cmake --install .If you want to specify a custom installation path:
cmake --install . --prefix "path/to/install/dir"Installed locations (default):
- Headers:
<prefix>/include/fastapi-cpp - Library:
<prefix>/lib/fastapi-cpp.a(or.libon Windows)
Once installed, FastAPI-CPP can be found automatically using find_package().
cmake_minimum_required(VERSION 3.15)
project(MyApp)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
find_package(FastAPI-CPP REQUIRED)
add_executable(my_app simple_example.cpp)
target_link_libraries(my_app FastAPI_CPP::fastapi-cpp)#include <fastapi-cpp/server.hpp>
#include <fastapi-cpp/macros.hpp>
Router app;
Response read_item(int item_id) {
return Response(json{{"item_id", item_id}});
}
Response create_user(std::string name, int age) {
return Response(json{{"name", name}, {"age", age}});
}
int main() {
APP_GET("/items/{item_id}", read_item, Path<int>);
APP_POST("/users", create_user, Query<std::string>, Query<int>);
FastApiCpp::run(app, "127.0.0.1", 8080);
}A more comprehensive example can be found examples
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release
./my_app.exeThis project builds on: