0

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

Iguramu
  • 2,080
  • 5
  • 26
  • 30
  • 1
    What do you mean by "Reservation room can be assigned to another room."? –  Aug 24 '09 at 12:17
  • I'd try to un-babby this but I can't figure out what he's asking –  Aug 24 '09 at 12:19

4 Answers4

2

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.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
0

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.

the_drow
  • 18,571
  • 25
  • 126
  • 193
  • If you check this site: http://stackoverflow.com/questions/207477/restful-url-design-for-search . As you see there is a relationship between cars and garage. So I think, if garage/yyy/cars is better option so room/4/reservation/15 is too. – Iguramu Aug 24 '09 at 12:47
  • It's just my two cents, you should do whatever you think is right. – the_drow Aug 24 '09 at 12:58
0

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.

aehlke
  • 15,225
  • 5
  • 36
  • 45
0

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.