0

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.

James Z
  • 12,209
  • 10
  • 24
  • 44
Anuj jain
  • 493
  • 1
  • 8
  • 26
  • Read about @javax.ws.rs.QueryParam annotation – kret Sep 19 '18 at 08:37
  • @QueryParam if use it will be static clauses. I want key-value can be any parameters passed in url not predefined like i have 4-5 fields in url 1 or more clauses can pe passed – Anuj jain Sep 19 '18 at 08:42

0 Answers0