-1

I'm defining a RESTful API for a TV broadcaster, specifically what the path should look like when asking for a subset of data. For example if I wanted to get the whole content for a particular channel, language on that channel between a specific date, how would I filter by date? The path below seems too long:

endpoint.com/content/channels/{channel_name}/language/french/from/20160701/to/20160801

An alternative I saw is to 'treat the search as a resource' and POST the date range filters to it in the request body, as mentioned here on SO: (How to design RESTful search/filtering?)

Any thoughts?

Community
  • 1
  • 1
blarg
  • 3,773
  • 11
  • 42
  • 71

2 Answers2

1

I also work for a TV Broadcaster and the approach we have taken is to post the search criteria through a resource. Much easier to handle and doesn't create an endless path.

Interface :

@POST
@Path("/lookup")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
List<Content> getContent(CriteriaSearch cr);

Implementation :

@Override
@Public
public List<ContentInfo> getContent(CriteriaSearch searchCriteria) {

        List<ContentInfo> contentInfos = contentManager.lookupContent(searchCriteria);

...

Pat B
  • 1,915
  • 23
  • 40
1

I will suggest you use @QueryParam annotation to filter your resources by getting it from URI.

To filter the resource you can use an URI like

/channel_name?language=french&from=20160701&to=20160801

Using JAX-RS you then can access the these values:

@GET
@Path("/channel_name")
List<Content> getContent(@QueryParam("language")String lang,
                         @QueryParam("from")Long from, 
                         @QueryParam("to")Long to) {
  // your logic
}

Of course you need to take care of exceptions and the repsonse including status codes in this case.

Sai prateek
  • 11,842
  • 9
  • 51
  • 66