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

  1. Entity for User
  2. Generic CRUD Service for User entity.

Usage

  1. extending a AGenericRest
  2. annotate class with @GenericRest annotation
  3. Then select some of the following annotations depending on your needs.

Method Annotations

AnnotationDescriptionHTTP MethodDefault URIRequest Body
GetAllget all entititesGET/-
GetByIdget entity by idGET/{id}-
Createcreate entityPOST/entity
Savecreate or update entityPOST/entity
Updateupdate entityPUT/entity
DeleteAlldelete all entitiesDELETE/-
DeleteByIddelete entity by idDELETE/{id}-
Deletedelete entityDELETE/entity

Exmaple RestController

Rest Response Builder

Default Respone Builder

  • RestError
  • RestErrorResponse
  • RestResponse