challenge on Nested resources url

23 Views Asked by At

How is a nested resource URL like /bikes/123/reviews different from an endpoint like /reviews?

I need help I expect to get to know of the difference between a nested resource URL like /bikes/123/reviews and an endpoint like /reviews?

1

There are 1 best solutions below

0
VoiceOfUnreason On

How is a nested resource URL like /bikes/123/reviews different from an endpoint like /reviews?

Not very much?

Both are perfectly satisfactory resource identifiers, compliant with the production rules defined in RFC 3986, both are pretty trivially expressed by URI templates.

One difference between the two spellings is that you can use dot-segments to move up the hierarchy of path segments; in other words, you can compute /bikes/123 from the context /bikes/123/reviews and the relative path ...

Resource identifiers are a lot like variable names: the machines don't care, and that's a good thing because it gives designers the ability to tailor their spelling conventions to make things easier for the people they care about.


Example:

/questions/78070804/challenge-on-nested-resources-url
/questions/78070804
/challenge-on-nested-resources-url

All three of these spellings are fine; the web browser would know what do do in each case without difficulty. The third spelling gives humans context, but risks collisions -- we're allowed to have more than one question with the same hint. The second spelling has no risks of collisions, but strips away the context. The first spelling gives the human readers context without risking collisions.


That said, a lot of today's conventions about resource models and resource identifiers has its roots in Rails 1.2. Therefore, it can help to be familiar with