I am working on designing the API's for the first time in Spring and I have the following use case:
- Get all the products.
- Get Products by ID.
Now, what I did was, I made a single API for this,
@Path("/products")
public interface ProductResource {
@GET
@ApiOperation(value = "Gets all the products by criteria")
Response getProductsByCriteria(@Context UriInfo uriInfo);
}
What I am doing is, I take the ID in the query param. If it's value is null, I will call the method (at service layer) for returning all products, else I will call the method for returning a specific product based on its id (coming in the query param).
I just want to know, is this a bad RESTFul Design? Should I instead have two seperate API's for getting products based on their ID's and for getting all the productS?