I am building a GET Service to fetch data from DB and show on UI. The data can be fetched using multiple filters clauses and I need pagination also. How to do it in Jersy DropWizard Framework?
I am thinking to do like this :
Path : /data/?username=val1entity&=val2&limit=10&offset=0
@Path("/audit")
@Produces(value = MediaType.APPLICATION_JSON)
@GET
public Response<List<AuditEvent>> getAuditEvents(@Context UriInfo uriInfo) {
logger.info("get Audit Events");
try {
MultivaluedMap<String,String> queryParams = uriInfo.getQueryParameters();
return new Response<>(
Response.Status.OK, "List of Audit Eents",
auditService.getAuditEvents(queryParams));
} catch (Exception e) {
}
}
public List<AuditEventDB.AuditEvent> getAuditEvents(MultivaluedMap<String,String> queryParams) {
List<AuditEventDB.AuditEvent> auditEvents = new ArrayList<>();
try {
auditEvents = auditEventDB.getAllAuditEvents();
}
catch(Exception e)
{
logger.info("Error in Getting Audit Events" ,e);
}
return auditEvents;
}
Is this correct way or is there a better approach to do this? I am new to rest framework.