Skip to content

Latest commit

 

History

History
59 lines (41 loc) · 1.16 KB

File metadata and controls

59 lines (41 loc) · 1.16 KB

InAPI

C++

InAPI is a C++ library for building HTTP servers with FastAPI-like syntax.

The project uses cpp-httplib and nlohmann/json.

Build

By default, the makefile builds src/main.cpp. Pass SRC to build another file:

make compile SRC=src/app.cpp
make SRC=src/app.cpp

Application Example

#include <InAPI.hpp>

int main() {
    App app;

    app.get("/", []() {
        return text("InAPI 2026 by Qualsu");
    });

    app.get("/users/{id:int}", [](Request request) {
        return json({
            {"id", request.param_int("id")},
            {"name", "Alex"}
        });
    });

    app.post("/users", [](Request request) {
        Json body = request.json();

        return json({
            {"created", true},
            {"name", body.value("name", "")}
        }, 201);
    });

    app.error_handler(404, [](Request) {
        return error(404, "Route not found");
    });

    app.run(8080);
}