Book Image

RESTful Java Web Services, Second Edition

Book Image

RESTful Java Web Services, Second Edition

Overview of this book

Table of Contents (17 chapters)
RESTful Java Web Services Second Edition
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Returning modified resources to the caller


In a typical REST request-response model, an API client reads a resource from the server, makes some modifications, and sends the modified resource back to the server to save the changes via the PUT, POST, or PATCH operations as appropriate. While persisting changes, there are chances that the server may modify some of the fields, such as the version field and the modification date. In such cases, it makes sense to return the modified resource representation back to the client in order to keep both the client and the server in sync. The following example returns the modified Department entity back to the caller:

@POST
@Path("{id}")
public Department editDepartment(@PathParam("id") Short id, Department entity) {
  Department modifiedEntity=editDepartmentEntity(entity);
  return modifiedEntity;
}

If you are using the POST operation for creating a resource, you can use the HTTP 201 status code in the response, indicating the status of operation, and...