Skip to content
This repository was archived by the owner on Jul 25, 2026. It is now read-only.

Latest commit

 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

how to use

include this server header

#include "api/server.hpp"

create a server instance

int main() {
  api::Server server;
}

how to add routes

to add a GET route

server.get("/customers", [](api::Request) -> api::Response {
  // do stuff and return a response
});

to build a response

api::Response response(200);
response.set_body(R"({"customers": ["jerry", "peter", "dennis"]})");

a complete GET route looks like this

server.get("/customers", [](api::Request) -> api::Response {
  api::Response response(200);
  response.set_body(R"({"customers": ["jerry", "peter", "dennis"]})");
  return response;
});

or you can return a response via .json files with load_response

return api::load_response("./database/patrons.json"); 

to return an error

return api::Response::error(404);

how to add middleware

to add a global middleware

server.use([](api::Request&) -> std::optional<api::Response> {
  // return an api::Response to short-circuit
  // return { } to move to move to the next middleware/route
});

how to start the server

use the start(port) method

server.start(8080);

the repo has an examples/ folder you can check. compile and run the routing example from the project root with:

g++ examples/routing_example.cpp -o routing_example && ./routing_example

installation

this is a header-only library, so no compilation needed. just drop the headers into your project.

option 1 - quick way

  1. download one of the include.zip releases.
  2. copy the api/ directory into your project's include folder.
  3. include the server header in your code: #include "api/server.hpp"

option 2 - cmake

  1. add this repository to your project.
  2. add these lines to your CMakeLists.txt:
# add the framework directory
add_subdirectory(third_party/RestfulApiFramework)

# link it to your executable
target_link_libraries(your_project_name PRIVATE RestAPI::framework)

requirements

  • Compiler: C++17 compatible compiler (GCC 7+, Clang 5+, or MSVC 19.14+).
  • Operating System: Linux / macOS (standard POSIX socket support).
  • Build System: CMake 3.10+ (optional, but recommended).

About

A rudimentary REST API framework built in C++.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages