Lukas Woodtli d2e60f59b3
Cpp restbed server improvements (#13030)
* Keep old implementation of cpp-restbed generator as cpp-restbed-server-deprecated

* Refactor operation path processing

* Restructure samples directory to better allow writing tests

* Improve templates for cpp-restbed-server

Improve templates

* Add integration tests

* Improvement in templates for cpp-restbed-server

* Fix tests

* Improve cpp-restbed generator

* Improve cpp-restbed-server

* Add more tests

* Add suppoert for arrays of enums in query params

* Generate CMakeLists.txt

* Small improvements and example in Readme

* Add integration tests to maven project

* Update doc
2022-08-27 18:10:28 +08:00
..

REST API Server for OpenAPI Petstore

Overview

This API Server was generated by the OpenAPI Generator project. It uses the Restbed Framework.

Installation

Put the package under your project folder and import the API stubs. You need to complete the server stub, as it needs to be connected to a source.

Libraries required

boost_system ssl (if Restbed was built with SSL Support) crypto pthread restbed

Namespaces

org.openapitools.server.api org.openapitools.server.model

Example

The handler functionality can be implemented in two different ways. Either inherit the given resource and override the handler methods. Or set a handler lambda to a resource.

This example shows how this can be done with the pet store API.

#include "api/StoreApi.h"
#include "api/UserApi.h"

using namespace org::openapitools::server::api;
using namespace org::openapitools::server::api::StoreApiResources;
using namespace org::openapitools::server::api::UserApiResources;

/* 1. variant: inherit from the resource and override handler method */
class MyStoreApiStoreOrderResource : public StoreOrderResource {
public:
    std::pair<int, Order>
    handler_POST(Order &order) override {
        auto ret = Order();
        /* ... add your implementation here .... */
        return std::make_pair(200, ret);
    }
};

int main() {
    const auto service = std::make_shared<restbed::Service>();

    auto storeApi = StoreApi(service);
    storeApi.setResource(std::make_shared<MyStoreApiStoreOrderResource>());

    auto userApi = UserApi(service);
    /* 2. variant: implement handler as lambda */
    userApi.getUserResource()->handler_POST_func = [](auto& user) {
        /* ... add your implementation here .... */
        return 200;};

    const auto settings = std::make_shared<restbed::Settings>();
    settings->set_port(1236);

    service->start(settings);
}