Go to file
Leonid Stryzhevskyi 49e63fbf15
Merge pull request #27 from oatpp/virtual_connection
Virtual connection
2018-12-16 14:36:56 +02:00
algorithm Renamed CRC32.hpp to CRC. Better static_wrapper_cast 2018-08-07 02:15:08 +03:00
codegen reuse connection in ApiClient 2018-11-11 00:51:56 +02:00
core oatpp/version increased to '0.18.12' 2018-12-16 02:56:31 +02:00
encoding constexpr removed. base64 test 2018-10-17 12:22:24 +03:00
network ControllerAsync for web::FullTest 2018-12-10 03:29:57 +02:00
parser/json constexpr removed. base64 test 2018-10-17 12:22:24 +03:00
test more tests added 2018-12-16 02:45:09 +02:00
web better simple and async web FullTest 2018-12-13 17:47:58 +02:00
.gitignore Initial commit 2018-03-13 03:52:44 +02:00
azure-pipelines.yml Build script for Mac added 2018-10-17 12:37:30 +03:00
CMakeLists.txt Fixed CMakeLists.txt 2018-12-16 03:00:13 +02:00
lgtm.yml lgtm.yml added 2018-10-17 21:54:45 +03:00
LICENSE Initial commit 2018-03-13 03:52:44 +02:00
README.md Update README.md 2018-10-22 16:26:33 +03:00

oat++ oatpp build status Language grade: C/C++ Join the chat at https://gitter.im/oatpp-framework/Lobby

Zero-Dependency. Performance oriented web-service-development framework. Organic. Pure C++.

Contributors wanted!
Pull requests and issues are welcome.

Features

  • Blazingly fast
  • Zero Dependency, no installations
  • Asynchronous server (High performance. Handle 30K+ simultaneous connections)
  • Multithreaded server (Simple API)
  • Connection agnostic. (Use whatever transport. Whatever SSL backend. Whatever sockets, pipes, files. etc. It cares about HTTP stream only)
  • REST framework (with ability to autodocument endpoints see oatpp-swagger)
  • Retrofit-like client wrapper (Use whatever request executor for example cURL, or minimalistic one provided out of the box)
  • Object mapping (Fast object serialization-deserialization. Currently JSON, more formats comes shortly)
  • Simple dependency injection framework
  • Simple Test framework
  • HTTP_1.1 (2.0 comes shortly)

Simple API overview

"Simple API" refers to as API used together with oatpp::web::server::HttpConnectionHandler utilizing multithreading plus blocking-IO approach.

Create Endpoint

ENDPOINT("GET", "demo/api/hello", hello) {
  return createResponse(Status::CODE_200, "Hello World!");
}

Pass parameters to endpoint

ENDPOINT("GET", "demo/api/param/{param}", getWithParams,
         PATH(String, param)) {
  return createResponse(Status::CODE_200, "param=" + param);
}

Return JSON

ENDPOINT("GET", "demo/api/json", getJson) {
  auto dto = MyDto::createShared();
  dto->statusCode = 200;
  dto->message = "Hello json";
  return createDtoResponse(Status::CODE_200, dto);
}

Output:

{"message": "Hello json", "statusCode": 200}

Post JSON body

ENDPOINT("POST", "demo/api/json", postJson,
         BODY_DTO(MyDto::ObjectWrapper, dto)) {
  auto dtoMessage = dto->message;
  return createResponse(Status::CODE_200, "dtoMessage: " + dtoMessage);
}

Terminal:

$ curl -X POST "localhost:8001/demo/api/json" -d '{"message": "hello json post"}'
dtoMessage: hello json post

Async API overview

"Async API" refers to as API used together with oatpp::web::server::AsyncHttpConnectionHandler utilizing oatpp-coroutines plus non-blocking-IO approach.

Create Endpoint Async

ENDPOINT_ASYNC("GET", "demo/api_async/hello", HelloAsync) {

  ENDPOINT_ASYNC_INIT(HelloAsync)

  Action act() override {
    return _return(controller->createResponse(Status::CODE_200, "Hello World Async API!"));
  }

};

Pass parameters to endpoint Async

ENDPOINT_ASYNC("GET", "demo/api_async/param/{param}", GetWithParamsAsync) {

  ENDPOINT_ASYNC_INIT(GetWithParamsAsync)

  Action act() override {
    auto param = request->getPathVariable("param");
    return _return(controller->createResponse(Status::CODE_200, "param=" + param));
  }

};

Return JSON Async

ENDPOINT_ASYNC("GET", "demo/api_async/json", GetJSONAsync) {

  ENDPOINT_ASYNC_INIT(GetJSONAsync)

  Action act() override {
    auto dto = MyDto::createShared();
    dto->statusCode = 200;
    dto->message = "Hello json";
    return _return(controller->createDtoResponse(Status::CODE_200, dto));
  }

};

Output:

{"message": "Hello json", "statusCode": 200}

Post JSON body Async

ENDPOINT_ASYNC("POST", "demo/api_async/json", PostJSONAsync) {

  ENDPOINT_ASYNC_INIT(PostJSONAsync)

  Action act() override {
    return request->readBodyToDtoAsync<MyDto>(this,
                                              &PostJSONAsync::onBodyObtained,
                                              controller->getDefaultObjectMapper());
  }

  Action onBodyObtained(const MyDto::ObjectWrapper& dto) {
    return _return(controller->createResponse(Status::CODE_200, "dtoMessage: " + dto->message));
  }

};

Terminal:

$ curl -X POST "localhost:8001/demo/api_async/json" -d '{"message": "hello json post"}'
dtoMessage: hello json post

Swagger documentation

ENDPOINT_INFO(createUser) {
  info->summary = "Create new User";
  info->addConsumes<UserDto::ObjectWrapper>("application/json");
  info->addResponse<UserDto::ObjectWrapper>(Status::CODE_200, "application/json");
}
ENDPOINT("POST", "demo/api/users", createUser,
         BODY_DTO(UserDto::ObjectWrapper, userDto)) {
  return createDtoResponse(Status::CODE_200, m_database->createUser(userDto));
}

How to start

Grab any project from examples, and follow README

Examples:

  • Media-Stream (Http-Live-Streaming) - Example project of how-to build HLS-streaming server using oat++ Async-API.
  • CRUD - Example project of how-to create basic CRUD endpoints.
  • AsyncApi - Example project of how-to use asynchronous API for handling large number of simultaneous connections.
  • ApiClient-Demo - Example project of how-to use Retrofit-like client wrapper (ApiClient) and how it works.
  • TLS-Libressl - Example project of how-to setup secure connection and serve via HTTPS.
  • Consul - Example project of how-to use oatpp::consul::Client. Integration with Consul.