Neither one is RESTful. The semantics of the URI should be irrelevant to a client in a RESTful application.
REST is an architectural style based on the web itself. Think about it. When you go to Stack Overflow, the only URI you're concerned about is stackoverflow.com
. Once you are logged in, you're redirected to your home page, and the URI of your home page is irrelevant. Right now I have at my menu bar a link that goes to my home page, you have an identical link that goes to your home page, and we don't care what the URI is when we click it, right? On our home page, we see questions and answers, and we don't care about their URIs either, only their title and description.
Now, let's reverse it. REST being is the architectural style of the web, if the web were like you think REST is, when you join stackoverflow.com
, instead of having a nice link with your name pointing to your home page you'd have a text saying "Your id is 131809, please, take the URI pattern /users/(id), replace id with this number, paste it in the address bar and you'll get to your homepage", and you think, "why those idiots don't make a link for that?"
That sounds ridiculous, but that's what most people think REST is. REST APIs must be hypertext driven.
This means that instead of being concerned if a user's orders should be at /customer/(customer_id)/orders
, or just /customer/orders
or even /orders
and rely on his credentials, forcing the client to know all these URI patterns, you should just give him a root document at your API entry point, that considers his credentials, and gives the URIs with standard titles and descriptions, just like any website does when you log in!
So, let's say you use JSON, and your API is myapi.com
. That should be the only URI a client knows. When he makes a GET
request to that root document, with the proper Authorization header, he should get a JSON document like:
{"orders": "http://myapi.com/customer/123456/orders"}
And obviously, he doesn't need to know what the value of "orders" is, only that it's a valid URI that will lead him to another resource containing a collection of his orders. That URI could be anything, its semantics doesn't matter. It could be your friend's suggestion:
{"orders": "http://myapi.com/orders"}
Or anything else, that could be changed anytime:
{"orders": "http://myapi.com/this/is/a/meaningless/uri"}
Of course, you should put some effort into having clear and meaningful URIs, but that doesn't make your API more or less RESTful. Where it bears on this matter, what makes your API RESTful is how your clients obtain the URIs, and if your clients are reading URI patterns in documentation and not getting them as links in other resources, your API is not RESTful. Simple as that.