tags:

views:

59

answers:

3

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

+2  A: 

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
Then if i chose option a), How should i establish relationship between Room and Reservation?
Iguramu
See my answer below.
the_drow
A: 

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
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
It's just my two cents, you should do whatever you think is right.
the_drow
A: 

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.

Wahnfrieden