Book Image

Building a RESTful Web Service with Spring

By : Ludovic Dewailly
Book Image

Building a RESTful Web Service with Spring

By: Ludovic Dewailly

Overview of this book

Table of Contents (17 chapters)
Building a RESTful Web Service with Spring
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Updating resources


Choosing URI formats is an important part of designing RESTful APIs. As seen earlier, rooms are accessed using the path, /rooms/{roomId}, and created under /rooms. And you might recall that as per the HTTP specification, PUT requests can result in creating entities if they do not exist. The decision to create new resources on update requests is up to the service designer. It does, however, affect the choice of path to use for such requests.

Semantically, PUT requests update entities stored under the supplied request URI. This means that update requests should use the same URI as GET requests: /rooms/{roomId}. However, this approach hinders the ability to support resource creation on update, since no room identifier is available.

The alternative path we can use is /rooms, with the room identifier passed in the body of the request. With this approach, PUT requests can be treated as POST requests when the resource does not contain an identifier.

Given that the first approach...