Reputation: 12410
I know that one of the main principles of REST is that you create a unique URL to every resource.
My question is, how are these URLs typically defined?
Upvotes: 0
Views: 143
Reputation: 142242
REST is an architectural style for building distributed systems. Which generally means that you have a client application and a server application. When your client application needs to access some piece of information on your server, then create an URL that you can use to identify that piece of information.
The structure of the URL is not really important to the client application, so use whatever structure is easiest with whatever server framework you are using.
Upvotes: 0
Reputation: 1465
That's up to you to decide. You should make it make sense and be as persistent as possible.
Examples:
/users/john.doe
for a username and
/users
for the collection of users.
You should take advantage of the hierarchical nature of URLs to do stuff like:
/users/john.doe/documents
To refer to the list of a user's documents. You should be very careful with how you structure this. Think carefully about what the potential consequences of your design are, because the resource URLs are among the most important design decisions for your service.
Upvotes: 1
Reputation: 4122
however you like. The URL could be completely opaque or the path of the URL could convey what kind of resource to expect.
You might want to follow the HATEOAS principle and make access to those URLs part of the hypertext you are delivering, so clients only need to know how to navigate, not how to construct certain URLs.
I.e. you could start off a root URL and make all the other resources reachable by navigation from there. Don't tie yourself into a specific URL template. This will only hamper your ability to extend and improve upon your REST API.
Upvotes: 0
Reputation: 10582
REST urls are defined the same way children are named: some people use family names (an existing corporate or project standard), some people look in a baby-names book (standards document? hah!), some people ask friends for advice (friends, mailing lists, etc), some people put off the decision and use default names like "Baby Boy Smith" and have to go through tedious renaming processes later (301 redirecte, etc), some people refuse to tell anyone what names they've picked until delivery day.
In short, there really isn't a typical. Standard form-generated urls (with ?name=value&name=value parameters) are perfectly valid REST urls. Many people prefer to encode those parameters into slashed paths, like http://example.com/restapi/name/value/name/value or with implicit positional names, http://example.com/restapi/value1/value2. But you are by no means restricted to those formats.
Upvotes: 1