1

Suppose I have two resoureces: carts and items. Items can be nested inside cart or can be not this way:

/carts/32658/items/screwdriver

/items/screwdriver

Does the same item in cart and not in cart are different resources in REST conventions?

igor_rb
  • 1,821
  • 1
  • 19
  • 34

2 Answers2

1

If you are talking about same screwdriver then they are same resources. One resource may have several URL's. In that case one of them is chosen to be official URL and is called Canonical URL. Official screwdriver URL might be /items/screwdriver where client might get full info about it.

nikita
  • 2,737
  • 2
  • 20
  • 26
  • i.e. in my `carts/32658/items/` resource I shold have link to `/items/screwdriver` resource with full info about item, and `/carts/32658/items/screwdriver` url shoud be disabled? – igor_rb Sep 26 '14 at 07:56
  • 1
    No you shouldn't disable `/carts/32658/items/screwdriver`. `/carts/32658/items/screwdriver` and `/items/screwdriver` are all URL's of the same resource. They may give you the same information(or may not) and same representation(one xml and another json). They all talk about the same thing(resource) - screwdriver. If you want to mark some URL as official you may add `Content- Location` header in `/carts/32658/items/screwdriver` pointing to canonical `/items/screwdriver`. Thus you are saying that official URL of screwdriver is here `/items/screwdriver`. – nikita Sep 26 '14 at 08:11
1

As other answers and comments have suggested there is no REST violation when having multiple URI to one resource and different sources and SO answers say so.

Each resource in a service suite will have at least one URI identifying it.

But I would rethink if you allow all HTTP methods on the second resource link. Given /carts/32658/items/screwdriver it might not good to allow PUT, because clients might think they will just change the screwdriver in cart #32658 and not the global screwdiver entity.

Community
  • 1
  • 1
Robert
  • 1,286
  • 1
  • 17
  • 37