Generic CRUD Rest
Introduction
Generic CRUD operations defined in service layer can be used in REST layer too.
To use Generic CRUD Rest Controller
feature you need following; Let's assume you have a table named as User
on database. Then you need;
Requirements
- Entity for User
Generic CRUD Service
forUser
entity.
Usage
- extending a
AGenericRest
- annotate class with
@GenericRest
annotation - Then select some of the following annotations depending on your needs.
Method Annotations
Annotation | Description | HTTP Method | Default URI | Request Body |
---|---|---|---|---|
GetAll | get all entitites | GET | / | - |
GetById | get entity by id | GET | /{id} | - |
Create | create entity | POST | / | entity |
Save | create or update entity | POST | / | entity |
Update | update entity | PUT | / | entity |
DeleteAll | delete all entities | DELETE | / | - |
DeleteById | delete entity by id | DELETE | /{id} | - |
Delete | delete entity | DELETE | / | entity |
Exmaple RestController
Rest Response Builder
Default Respone Builder
- RestError
- RestErrorResponse
- RestResponse