Frage

Here's an example URL:

/users/123/comments

Based on this URL, which term would best describe users? Is users the resource or is it a part of the resource. What would be the name of that part?

The same question goes for the other parts. Which terms would best describe 123 and comments?

Is there a term that would refer to the second part of RESTful URLs? It would describe 123 in /users/123 and purchases in /me/purchases.

War es hilfreich?

Lösung

REST is a Resource-Oriented. URLs represent resources.

In your example, /users/123/comments:

  • users is a resource.
  • 123 is the unique identifier of an user.
  • In this case, comments are a sub-resource of users, but they are probably resources on their own (ex. calling /comments/{id})

About your second question, the format for /me/purchases is not the same as /users/123. And /me/purchases is probably a short URL for something like /users/{myid}/purchases where purchases are a sub-resource of users (and probably a resource on their own also, available by /purchases/{id}).


For more information, here is a video, that is not directly related to your question, but that is very well made and very interesting about REST web services.

Andere Tipps

In your example, http://example.org/users/123/comments points to a resource. A complete URI is an identifier for a resource.

Let me give you an extreme example,

/users/123/comments.xml

/users/123/comments.json

are two different resources.

The query string also identifies resources, so

/users/123/comments?format=xml

/users/123/comments?format=json

are also two different resources.

Resources do not map to entities. Resources are "some concept" that you wish to expose over HTTP and have identified with a URI.

In RESTful system URIs are opaque to the system design. A client of your system should not try and infer meaning from portions of your URI. A server can setup conventions to help it build a URI space, but these are private implementation details of the server.

There is no such thing as a RESTFul url. The term is a fabrication of framework designers and will just serve to confuse you.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top