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 8a5ad5c88b memory pools: Remove std::call_once. | 3 ani în urmă | |
---|---|---|
.github | 3 ani în urmă | |
changelog | 3 ani în urmă | |
cmake | 5 ani în urmă | |
src | 3 ani în urmă | |
test | 3 ani în urmă | |
utility | 5 ani în urmă | |
.gitignore | 3 ani în urmă | |
CMakeLists.txt | 4 ani în urmă | |
CODE_OF_CONDUCT.md | 5 ani în urmă | |
CONTRIBUTING.md | 5 ani în urmă | |
LICENSE | 6 ani în urmă | |
README.md | 3 ani în urmă | |
azure-pipelines.yml | 4 ani în urmă | |
lgtm.yml | 5 ani în urmă |
Attention
1.2.0
is now merged to Master and soon will receive a release tag. Get ready to migrate - see the changelog for details.1.1.0
code use this commit - e577681355ca652f317867c609e07cefabc37c0aOat++ 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.
Start
About
Join Our Community
For more info see Api Controller
ENDPOINT("PUT", "/users/{userId}", putUser,
PATH(Int64, userId),
BODY_DTO(Object<UserDto>, 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(Object<UserDto>, 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(Object<UserDto>, 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<Object<UserDto>>("application/json");
info->addResponse<Object<UserDto>>(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(Object<UserDto>, 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<oatpp::Object<UserDto>>(objectMapper);
For more info see Data Transfer Object (DTO).
class UserDto : public oatpp::DTO {
DTO_INIT(UserDto, DTO)
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);
Output:
{
"id": 1,
"name": "Ivan"
}
While DTO objects apply strict rules on data ser/de, you can also
serialize/deserialize data in free form using type oatpp::Any
.
oatpp::Fields<oatpp::Any> map = {
{"title", oatpp::String("Hello Any!")},
{"listOfAny",
oatpp::List<oatpp::Any>({
oatpp::Int32(32),
oatpp::Float32(0.32),
oatpp::Boolean(true)
})
}
};
auto json = mapper->writeToString(map);
Output:
{
"title": "Hello Any!",
"listOfAny": [
32,
0.3199999928474426,
true
]
}