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.
lganzzzo d48a65f59b Increase oatpp version to '0.19.10' | 4 yıl önce | |
---|---|---|
cmake | 5 yıl önce | |
src | 4 yıl önce | |
test | 4 yıl önce | |
utility | 5 yıl önce | |
.gitignore | 4 yıl önce | |
CMakeLists.txt | 4 yıl önce | |
CODE_OF_CONDUCT.md | 5 yıl önce | |
CONTRIBUTING.md | 5 yıl önce | |
LICENSE | 6 yıl önce | |
README.md | 4 yıl önce | |
azure-pipelines.yml | 4 yıl önce | |
lgtm.yml | 5 yıl önce |
Oat++ is the 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 small memory footprint.
Contributors wanted!
Join the community
For more info see Api Controller
ENDPOINT("PUT", "/users/{userId}", putUser,
PATH(Int64, userId),
BODY_DTO(dto::UserDto::ObjectWrapper, userDto))
{
userDto->id = userId;
return createDtoResponse(Status::CODE_200, m_database->updateUser(userDto));
}
For more info see Api Controller / CORS
ADD_CORS(putUser)
ENDPOINT("PUT", "/users/{userId}", putUser,
PATH(Int64, userId),
BODY_DTO(dto::UserDto::ObjectWrapper, userDto))
{
userDto->id = userId;
return createDtoResponse(Status::CODE_200, m_database->updateUser(userDto));
}
For more info see Api Controller / Authorization
using namespace oatpp::web::server::handler;
ENDPOINT("PUT", "/users/{userId}", putUser,
AUTHORIZATION(std::shared_ptr<DefaultBasicAuthorizationObject>, authObject),
PATH(Int64, userId),
BODY_DTO(dto::UserDto::ObjectWrapper, userDto))
{
OATPP_ASSERT_HTTP(authObject->userId == "Ivan" && authObject->password == "admin", Status::CODE_401, "Unauthorized");
userDto->id = userId;
return createDtoResponse(Status::CODE_200, m_database->updateUser(userDto));
}
For more info see Endpoint Annotation And API Documentation
ENDPOINT_INFO(putUser) {
// general
info->summary = "Update User by userId";
info->addConsumes<dto::UserDto::ObjectWrapper>("application/json");
info->addResponse<dto::UserDto::ObjectWrapper>(Status::CODE_200, "application/json");
info->addResponse<String>(Status::CODE_404, "text/plain");
// params specific
info->pathParams["userId"].description = "User Identifier";
}
ENDPOINT("PUT", "/users/{userId}", putUser,
PATH(Int64, userId),
BODY_DTO(dto::UserDto::ObjectWrapper, userDto))
{
userDto->id = userId;
return createDtoResponse(Status::CODE_200, m_database->updateUser(userDto));
}
For more info see Api Client
class UserService : public oatpp::web::client::ApiClient {
public:
API_CLIENT_INIT(UserService)
API_CALL("GET", "/users", getUsers)
API_CALL("GET", "/users/{userId}", getUserById, PATH(Int64, userId))
};
auto response = userService->getUserById(id);
auto user = response->readBodyToDto<dto::UserDto>(objectMapper);
For more info see Data Transfer Object (DTO).
class UserDto : public oatpp::data::mapping::type::Object {
DTO_INIT(UserDto, Object)
DTO_FIELD(Int64, id);
DTO_FIELD(String, name);
};
using namespace oatpp::parser::json::mapping;
auto user = UserDto::createShared();
user->id = 1;
user->name = "Ivan";
auto objectMapper = ObjectMapper::createShared();
auto json = objectMapper->writeToString(user);