https://github.com/oatpp/example-crud
A complete example of a "CRUD" service (UserService) built with Oat++.
https://github.com/oatpp/example-crud
cpp crud-api oatpp orm sqlite3 swagger-ui
Last synced: 3 months ago
JSON representation
A complete example of a "CRUD" service (UserService) built with Oat++.
- Host: GitHub
- URL: https://github.com/oatpp/example-crud
- Owner: oatpp
- License: apache-2.0
- Created: 2019-01-27T22:59:55.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-06-26T19:20:05.000Z (11 months ago)
- Last Synced: 2024-10-29T22:52:14.759Z (6 months ago)
- Topics: cpp, crud-api, oatpp, orm, sqlite3, swagger-ui
- Language: C++
- Homepage: https://oatpp.io/
- Size: 70.3 KB
- Stars: 100
- Watchers: 7
- Forks: 63
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Example-CRUD [](https://dev.azure.com/lganzzzo/lganzzzo/_build?definitionId=9?branchName=master)
A complete example of a "CRUD" service (UserService) built with Oat++.
In this example:
- How to create CRUD endpoint.
- How to use [oatpp ORM](https://oatpp.io/docs/components/orm/#high-level-overview) - SQLite example.
- How to document API with Swagger-UI and OpenApi 3.0.0.More about Oat++:
- [Oat++ Website](https://oatpp.io/)
- [Oat++ Github Repository](https://github.com/oatpp/oatpp)
- [Get Started](https://oatpp.io/docs/start)## Overview
This project is using the following oatpp modules:
- [oatpp](https://github.com/oatpp/oatpp)
- [oatpp-swagger](https://github.com/oatpp/oatpp-swagger)
- [oatpp-sqlite](https://github.com/oatpp/oatpp-sqlite)### Project layout
```
|- CMakeLists.txt // projects CMakeLists.txt
|- sql/ // SQL migration scripts for SQLite database
|- src/
| |
| |- controller/ // Folder containing REST Controllers (UserController)
| |- db/ // Folder containing the database client
| |- dto/ // DTOs are declared here
| |- service/ // Service business logic classes (UserService)
| |- AppComponent.hpp // Service config
| |- DatabaseComponent.hpp // Database config
| |- SwaggerComponent.hpp // Swagger-UI config
| |- App.cpp // main() is here
|
|- test/ // test folder
|- utility/install-oatpp-modules.sh // utility script to install required oatpp-modules.
```---
### Build and Run
#### Using CMake
##### Pre Requirements
- `oatpp`
- `oatpp-swagger`
- `oatpp-sqlite` with `-DOATPP_SQLITE_AMALGAMATION=ON` cmake flag.**Note:** You may run `utility/install-oatpp-modules.sh` script to install required oatpp modules.
##### Build Project
```
$ mkdir build && cd build
$ cmake ..
$ make
$ ./crud-exe # - run application.
```#### In Docker
```
$ docker build -t example-crud .
$ docker run -p 8000:8000 -t example-crud
```---
### Endpoints
#### HTML
|HTTP Method|URL|Description|
|---|---|---|
|`GET`|http://localhost:8000/ | Root page |
|`GET`|http://localhost:8000/swagger/ui | Swagger UI page |#### User Service
|HTTP Method|URL|Description|
|---|---|---|
|`POST`|http://localhost:8000/users | Create new User |
|`PUT`|http://localhost:8000/users/{userId} | Update User by ID |
|`GET`|http://localhost:8000/users/{userId} | Get User by ID |
|`DELETE`|http://localhost:8000/users/{userId} | Delete User by ID |
|`GET`|http://localhost:8000/users/offset/{offset}/limit/{limit} | Get All Users with Paging |