I have one search widget where people search for car dealers by zip code. There are also some optional checkboxes to refine search in that widget.
Here is the URI for searching dealer by zip code.
http://localhost:8080/dealer/zip/10080
If user selects checboxes then the URI will be
http://localhost:8080/dealer/zip/10080servicetype=type1&servicetype=type2&servicetype=type3
I am using jersey. Here is java code.
@Path("/dealer")
@Produces(MediaType.APPLICATION_JSON)
public class DealerLocatorRS {
private DealerService dealerService=new DealerService();
@GET
@Path("/zip/{zip}")
public List<Dealer> getByZip(@PathParam("zip") String zip,
@QueryParam("servicetype") List<String> servicetype){
.. . ..
}
Is this right approach to pass optional and multiple values and . Can anybody help me to apply best practices?
I’m not sure that I’d map a search for dealers in a particular zip code to a resource; it doesn’t feel quite right. Instead, I’d have a resource that lists all the dealers, with individual dealers being sub-resources of that. If it was possible to return a subset of the list of subresources restricted by properties (e.g., their zip code) then that would be a great way to implement a search, otherwise I’d have a separate search handler that returns a list of links to matching dealer resources.