Skip to content

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.

Notifications You must be signed in to change notification settings

7bitcoder/SevenBitRest

Repository files navigation

Ubuntu Windows MacOs

logo

C++20 simple http rest framework!


Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Prebuild Binaries
  5. License
  6. Contact

About The Project

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.

Built With

Testing Utilities

Getting Started

To use library download prebuild binaries and link dynamic library, or build project locally

Prerequisites

Install Cmake if not already installed:

https://cmake.org/

Install Conan:

https://conan.io/

Build Framework Locally

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

Prepare

  1. Clone the repo
    git clone https://github.com/7bitcoder/SevenBitRest.git

Install Conan Packages

  1. Create and navigate to build directory
    mkdir build && cd ./build
  2. Install conan packages
    conan install --build=missing ..
  3. Navigate up
    cd ..

Install BoostUrl Library

  1. Create and navigate to BoostUrl directory
    mkdir BoostUrl && cd ./BoostUrl
  2. Clone BoostUrl repository
    git clone https://github.com/boostorg/url.git
  3. Navigate up
    cd ..

Build Framework

  1. Configure project
    cmake -B ./build 
  2. Build project
    cmake --build ./build

Usage

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

Hello World

#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

Dependency Injection

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();
}

Middlewares

7BitRest has also middleware system that is well known from other frameworks

Prebuild Binaries

License

Distributed under the MIT License. See LICENSE.txt for more information.

Contact

Project Link: https://github.com/7bitcoder/SevenBitRest

@7bitcoder 2022

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published