How to name Resource Identifiers?

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


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.


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.


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.

链接地址: http://www.djcxy.com/p/12080.html

上一篇: RDF和uuid。 为什么没有金塔纲要?

下一篇: 如何命名资源标识符?