Table of Contents
SevenBitRest is a simple C++ http rest framework, designed to be as easy to use as possible, the main inspiration was asp net core minimal api.
To use library download prebuild binaries and link dynamic library, or build project locally
Install Cmake if not already installed:
Install Conan:
Framework uses BoostUrl library, it is not yet part of official boost library so it must be installed separately (clone git repo in BoostUrl directory), also to build project benchmarks/examples/tests cmake cache flags should be set (using cmake-gui or in cli):
- Benchmarks - BUILD_BENCHMARKS
- Examples - BUILD_EXAMPLES
- Tests - BUILD_TESTS
- Clone the repo
git clone https://github.com/7bitcoder/SevenBitRest.git
- Create and navigate to build directory
mkdir build && cd ./build
- Install conan packages
conan install --build=missing ..
- Navigate up
cd ..
- Create and navigate to BoostUrl directory
mkdir BoostUrl && cd ./BoostUrl
- Clone BoostUrl repository
git clone https://github.com/boostorg/url.git
- Navigate up
cd ..
- Configure project
cmake -B ./build
- Build project
cmake --build ./build
Framework uses asp net core minimal api approach, to build endpoints use Map functions on SevenBitRest object. If not specified app will run on 9090 port by default.
For more examples, please refer to the Documentation
#include "SevenBitRest.hpp"
using namespace std::string_literals;
using namespace sb;
int main()
{
SevenBitRest rest;
rest.mapGet("/", []() { return "Hello, world!"s; });
rest.run();
}
Open link http://localhost:9090 to see results
Framework has build in dependency injection system, usage looks similar to asp net core
#include "SevenBitRest.hpp"
using namespace std;
using namespace sb;
struct Service
{
string helloFromService() { return "Hello from service."; }
};
int main()
{
SevenBitRest rest;
auto &services = rest.getServices();
services.addScoped<Service>();
rest.mapGet("/", [](Service &service) { return service.helloFromService(); });
rest.run();
}
7BitRest has also middleware system that is well known from other frameworks
Distributed under the MIT License. See LICENSE.txt
for more information.
Project Link: https://github.com/7bitcoder/SevenBitRest
@7bitcoder 2022