The REST project defines several identifiers for a resource that should be open to clients.

I would like to ask a question about the design of the HTTP REST API that I am viewing.

I sometimes have to access the widget with id 3:

http://ourserver/service/widgets/3

Get widget with ID 3

But I also sometimes need to access the widget using SKU #.

Is it wrong to expose the same resource through 2 URLs?

BUt I need my clients to get a widget with either its identifier or its SKU.

Which of the following is better?

  • http://ourserver/service/widgets/bysku/skyunumber
  • http://ourserver/service/widgets/skyunumber?idtype=sku

Again, I need my clients to be able to search the widget in two different ways. What is the best way to create urls?

+6
rest
source share
1 answer

I would suggest considering the following:

 GET http://ourserver/service/widgets?sku=34342323 => 303 See Other Location: http://ourserver/service/widgets/43 GET http://ourserver/service/widgets/43 

Using redirection, you can support any number of criteria for finding widgets. The key issue to consider is what happens when you start activating caching. If you return views from multiple URLs, you end up infecting the cache with multiple copies, and this makes invalid copies in the cache invalid when updating.

+13
source share

All Articles