REST API Action Definition Interface

The interface RestApiAction<M, D, U> will guide you for all common functionality, if you implement this interface into Controller and Service then you will get formatted code for basic operation, like as CRUD and Bulk CRUD.


RestApiAction<M, D, U> : Aim for manage

  • M (MasterDTO) : Minimum fields.

  • D (DetailsDTO) : Extend MasterDTO and with all fields.

  • U (UpdateDTO) : Extend DetailsDTO with an id filed for various operation.


Available Methods

Here giving you all methods argument and return with example JSON. Please see the example DTO

MessageResponse create(RequestData<D> data)

This is create method structure which takes DetailsDTO and process to save.

Example Request in JSON Format:

{
  "data": {
    "address": "Dhaka, Bangladesh",
    "age": 28,
    "email": "problemfighter.com@gmail.com",
    "firstName": "Touhid",
    "lastName": "Mia",
    "gender": "Male",
    "mobile": "123456",
    "occupation": "Software Engineer"
  }
}

Example Response in JSON Format:

{
  "status": "success",
  "code": "1200",
  "message": {
    "text": "Created",
    "key": "created"
  }
}


BulkResponse<D> bulkCreate(RequestBulkData<D> data)

Example Request in JSON Format:

{
  "data": [
    {
      "address": "Dhaka, Bangladesh",
      "age": 28,
      "email": "problemfighter.com@gmail.com",
      "firstName": "Touhid",
      "lastName": "Mia",
      "gender": "Male",
      "mobile": "123456",
      "occupation": "Software Engineer"
    },
    {
      "address": "Rangpur, Bangladesh",
      "age": 20,
      "email": "email@email.local",
      "firstName": "Person",
      "lastName": "One",
      "gender": "Male",
      "mobile": "123456",
      "occupation": "Software QA"
    },
    {
      "address": "Rajshahi, Bangladesh",
      "age": 21,
      "email": "email1@email.local",
      "firstName": "Person",
      "lastName": "Two",
      "gender": "Female",
      "mobile": "123456",
      "occupation": "Software Designer"
    },
    {
      "address": "Chittagong, Bangladesh",
      "age": 22,
      "email": "email2@email.local",
      "firstName": "Person",
      "lastName": "Three",
      "gender": "Male",
      "mobile": "123456",
      "occupation": "DevOps"
    },
    {
      "address": "Sylhet, Bangladesh",
      "age": 23,
      "email": "email13@email.local",
      "firstName": "Person",
      "lastName": "Four",
      "gender": "Female",
      "mobile": "123456",
      "occupation": "Software Designer"
    }
  ]
}

Example Response in JSON Format:

{
  "status": "partial",
  "code": "1212",
  "success": [
    {
      "id": 2,
      "firstName": "Person",
      "lastName": "One",
      "mobile": "123456",
      "gender": "Male",
      "age": 20,
      "address": "Rangpur, Bangladesh",
      "email": "email@email.local",
      "occupation": "Software QA"
    },
    {
      "id": 3,
      "firstName": "Person",
      "lastName": "Two",
      "mobile": "123456",
      "gender": "Female",
      "age": 21,
      "address": "Rajshahi, Bangladesh",
      "email": "email1@email.local",
      "occupation": "Software Designer"
    },
    {
      "id": 4,
      "firstName": "Person",
      "lastName": "Three",
      "mobile": "123456",
      "gender": "Male",
      "age": 22,
      "address": "Chittagong, Bangladesh",
      "email": "email2@email.local",
      "occupation": "DevOps"
    },
    {
      "id": 5,
      "firstName": "Person",
      "lastName": "Four",
      "mobile": "123456",
      "gender": "Female",
      "age": 23,
      "address": "Sylhet, Bangladesh",
      "email": "email13@email.local",
      "occupation": "Software Designer"
    }
  ],
  "failed": [
    {
      "error": {
        "message": {
          "text": "Email already exist",
          "key": "email.already.exist"
        }
      },
      "object": {
        "firstName": "Touhid",
        "lastName": "Mia",
        "mobile": "123456",
        "gender": "Male",
        "age": 28,
        "address": "Dhaka, Bangladesh",
        "email": "problemfighter.com@gmail.com",
        "occupation": "Software Engineer"
      }
    }
  ]
}


PageableResponse<M> list(Integer page, Integer size, String sort, String field, String search)

Example Response in JSON Format:

{
  "status": "success",
  "code": "1200",
  "data": [
    {
      "id": 5,
      "firstName": "Person",
      "lastName": "Four",
      "mobile": "123456",
      "gender": "Female",
      "age": 23
    },
    {
      "id": 4,
      "firstName": "Person",
      "lastName": "Three",
      "mobile": "123456",
      "gender": "Male",
      "age": 22
    },
    {
      "id": 3,
      "firstName": "Person",
      "lastName": "Two",
      "mobile": "123456",
      "gender": "Female",
      "age": 21
    },
    {
      "id": 2,
      "firstName": "Person",
      "lastName": "One",
      "mobile": "123456",
      "gender": "Male",
      "age": 20
    },
    {
      "id": 1,
      "firstName": "Touhid",
      "lastName": "Mia",
      "mobile": "123456",
      "gender": "Male",
      "age": 28
    }
  ],
  "pagination": {
    "total": 5,
    "totalPage": 1,
    "page": 0,
    "itemPerPage": 15
  }
}


PageableResponse<D> detailList(Integer page, Integer size, String sort, String field, String search)

Example Response in JSON Format:

{
  "status": "success",
  "code": "1200",
  "data": [
    {
      "id": 5,
      "firstName": "Person",
      "lastName": "Four",
      "mobile": "123456",
      "gender": "Female",
      "age": 23,
      "address": "Sylhet, Bangladesh",
      "email": "email13@email.local",
      "occupation": "Software Designer"
    },
    {
      "id": 4,
      "firstName": "Person",
      "lastName": "Three",
      "mobile": "123456",
      "gender": "Male",
      "age": 22,
      "address": "Chittagong, Bangladesh",
      "email": "email2@email.local",
      "occupation": "DevOps"
    },
    {
      "id": 3,
      "firstName": "Person",
      "lastName": "Two",
      "mobile": "123456",
      "gender": "Female",
      "age": 21,
      "address": "Rajshahi, Bangladesh",
      "email": "email1@email.local",
      "occupation": "Software Designer"
    },
    {
      "id": 2,
      "firstName": "Person",
      "lastName": "One",
      "mobile": "123456",
      "gender": "Male",
      "age": 20,
      "address": "Rangpur, Bangladesh",
      "email": "email@email.local",
      "occupation": "Software QA"
    },
    {
      "id": 1,
      "firstName": "Touhid",
      "lastName": "Mia",
      "mobile": "123456",
      "gender": "Male",
      "age": 28,
      "address": "Dhaka, Bangladesh",
      "email": "problemfighter.com@gmail.com",
      "occupation": "Software Engineer"
    }
  ],
  "pagination": {
    "total": 5,
    "totalPage": 1,
    "page": 0,
    "itemPerPage": 15
  }
}


DetailsResponse<D> details(Long id)

Example Response in JSON Format:

{
  "status": "success",
  "code": "1200",
  "data": {
    "id": 5,
    "firstName": "Person",
    "lastName": "Four",
    "mobile": "123456",
    "gender": "Female",
    "age": 23,
    "address": "Sylhet, Bangladesh",
    "email": "email13@email.local",
    "occupation": "Software Designer"
  }
}


MessageResponse update(RequestData<U> data)

Example Request in JSON Format:

{
  "data":     {
    "id": 5,
    "firstName": "Person",
    "lastName": "Four",
    "mobile": "123456",
    "gender": "Female",
    "age": 20,
    "address": "Khulna, Bangladesh",
    "email": "email13@email.local",
    "occupation": "Software Designer"
  }
}

Example Response in JSON Format:

{
  "status": "success",
  "code": "1200",
  "message": {
    "text": "Updated",
    "key": "updated"
  }
}


BulkResponse<U> bulkUpdate(RequestBulkData<U> data)

Example Request in JSON Format:

{
  "data": [
    {
      "id": 5,
      "firstName": "Person",
      "lastName": "Four",
      "mobile": "123456",
      "gender": "Female",
      "age": 50,
      "address": "NYC, USA",
      "email": "email13@email.local",
      "occupation": "Software Designer"
    },
    {
      "id": 2,
      "firstName": "Person",
      "lastName": "One",
      "mobile": "987654321",
      "gender": "Male",
      "age": 20,
      "address": "Rangpur, Bangladesh",
      "email": "email@email.local",
      "occupation": "Software QA"
    },
    {
      "id": 100,
      "firstName": "Touhid",
      "lastName": "Mia",
      "mobile": "123456",
      "gender": "Male",
      "age": 24,
      "address": "Dhaka, Bangladesh",
      "email": "problemfighter.com@gmail.com",
      "occupation": "Senior Software Engineer"
    }
  ]
}

Example Response in JSON Format:

{
  "status": "partial",
  "code": "1212",
  "success": [
    {
      "id": 2,
      "firstName": "Person",
      "lastName": "One",
      "mobile": "987654321",
      "gender": "Male",
      "age": 20,
      "address": "Rangpur, Bangladesh",
      "email": "email@email.local",
      "occupation": "Software QA"
    },
    {
      "id": 5,
      "firstName": "Person",
      "lastName": "Four",
      "mobile": "123456",
      "gender": "Female",
      "age": 50,
      "address": "NYC, USA",
      "email": "email13@email.local",
      "occupation": "Software Designer"
    }
  ],
  "failed": [
    {
      "error": {
        "message": {
          "text": "Unable to process update",
          "key": "unable.to.process.update"
        }
      },
      "object": {
        "id": 100,
        "firstName": "Touhid",
        "lastName": "Mia",
        "mobile": "123456",
        "gender": "Male",
        "age": 24,
        "address": "Dhaka, Bangladesh",
        "email": "problemfighter.com@gmail.com",
        "occupation": "Senior Software Engineer"
      }
    }
  ]
}


MessageResponse bulkDelete(RequestBulkData<Long> data)

Example Request in JSON Format:

{
  "data": [
    5,4,3
  ]
}

Example Response in JSON Format:

{
  "status": "success",
  "code": "1200",
  "message": {
    "text": "Deleted",
    "key": "deleted"
  }
}


MessageResponse hardDelete(RequestBulkData<Long> data)

Example Request in JSON Format:

{
  "data": [
    3, 4
  ]
}

Example Response in JSON Format:

{
  "status": "success",
  "code": "1200",
  "message": {
    "text": "Deleted",
    "key": "deleted"
  }
}


MessageResponse delete(Long id)

Example Response in JSON Format:

{
  "status": "success",
  "code": "1200",
  "message": {
    "text": "Deleted",
    "key": "deleted"
  }
}


PageableResponse<M> trash(Integer page, Integer size, String sort, String field, String search)

Example Response in JSON Format:

{
  "status": "success",
  "code": "1200",
  "data": [
    {
      "id": 5,
      "firstName": "Person",
      "lastName": "Four",
      "mobile": "123456",
      "gender": "Female",
      "age": 50
    },
    {
      "id": 1,
      "firstName": "Touhid",
      "lastName": "Mia",
      "mobile": "123456",
      "gender": "Male",
      "age": 28
    }
  ],
  "pagination": {
    "total": 2,
    "totalPage": 1,
    "page": 0,
    "itemPerPage": 15
  }
}


MessageResponse bulkRestore(RequestBulkData<Long> data)

Example Request in JSON Format:

{
  "data": [
    5,4
  ]
}

Example Response in JSON Format:

{
  "status": "success",
  "code": "1200",
  "message": {
    "text": "Restored",
    "key": "restored"
  }
}