Oat++ is a modern Web Framework for C++. It's fully loaded and contains all necessary components for effective production level development. It's also light and has a small memory footprint.
Leonid Stryzhevskyi 7cf4d9e769 Update README.md | 4 жил өмнө | |
---|---|---|
cmake | 5 жил өмнө | |
src | 4 жил өмнө | |
test | 4 жил өмнө | |
utility | 5 жил өмнө | |
.gitignore | 4 жил өмнө | |
CMakeLists.txt | 4 жил өмнө | |
CODE_OF_CONDUCT.md | 5 жил өмнө | |
CONTRIBUTING.md | 5 жил өмнө | |
LICENSE | 6 жил өмнө | |
README.md | 4 жил өмнө | |
azure-pipelines.yml | 4 жил өмнө | |
lgtm.yml | 5 жил өмнө |
Modern Web Framework for C++. High performance, simple API, cross platform, zero dependency.
Works on Linux/Unix/Windows. See full list of supported-platforms.
Contributors wanted!
Join the community
"Simple API" refers to as API used together with oatpp::web::server::HttpConnectionHandler
utilizing multithreading plus blocking-IO approach.
ENDPOINT("GET", "demo/api/hello", hello) {
return createResponse(Status::CODE_200, "Hello World!");
}
ENDPOINT("GET", "demo/api/param/{param}", getWithParams,
PATH(String, param)) {
return createResponse(Status::CODE_200, "param=" + param);
}
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}
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" refers to as API used together with oatpp::web::server::AsyncHttpConnectionHandler
utilizing oatpp-coroutines plus non-blocking-IO approach.
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!"));
}
};
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));
}
};
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}
ENDPOINT_ASYNC("POST", "demo/api_async/json", PostJSONAsync) {
ENDPOINT_ASYNC_INIT(PostJSONAsync)
Action act() override {
return request->readBodyToDtoAsync<MyDto>(controller->getDefaultObjectMapper()).callbackTo(&PostJSONAsync::onBodyObtained);
}
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
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));
}
Grab any project from examples, and follow README