Reputation: 2110
I have a Restful web service. Reservation room can change. Which URI is better solution?
a) http://localhost/hotel/Xhotel/Reservation/15
b) http://localhost/hotel/Xhotel/Room/4/Reservation/15
c) http://localhost/hotel/Xhotel/Reservation/15/Room/4
Upvotes: 0
Views: 264
Reputation: 11
The problem is not the URL or URI, The problem is if the Request to this 3 choices you described above is just for beautify the LINK or your going to grab or get all results from the requests like :
a)
$_GET['hotel'] = "Xhotel";
$_GET['Reservation'] = 15;
b)
$_GET['hotel'] = "Xhotel";
$_GET['Room'] = 4;
$_GET['Reservation'] = 15;
c)
$_GET['hotel'] = "Xhotel";
$_GET['Reservation'] = 15;
$_GET['Room'] = 4;
This is what we can get from the 3 format of URIs you have and the 2 last are the same.
If you are going to exploit the data from the requests it is okay, if not this will just make your programs looks bigger without effect so am suggesting the first if your doing only Reservation
Try to make the make the Reservation ID as a UUID v3 or v5 based on hotel UUID, to make them unique.
Upvotes: 0
Reputation: 15860
Each representation of the resource should only have a single URI. If the reservation is the important part, and the room can change, then don't include the room number in the URI. However, REST doesn't particularly care what your URIs look like, as long as you follow its constraints.
Upvotes: 0
Reputation: 19201
First of all you write RESTful. REST is an abbreviation.
Second, imo you should access them by Reservation ID so the first option is the best.
Reservation (Unique Key: Reservation ID) has many Rooms (Forign Key: Reservation ID).
Use the second option to see what reservations are on a specific room.
Also you can use the third option to show data about a room in the reservation.
Upvotes: 0
Reputation: 308269
That depends only on your requirements.
For example if a reservation can span multiple rooms then options b) and c) wouldn't be good URLs to access the full reservation.
Another question is if your reservation IDs are unique among all rooms or if the room ID is needed as well to uniquely identify a reservation.
Upvotes: 2