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

Asynchronous execution of RESTful web APIs


If your RESTful web API takes a considerable amount of time for finishing the job and the users cannot wait for the API to finish, you may want to consider using the asynchronous mode of execution.

The asynchronous RESTful web API works as explained here. The client calls the asynchronous RESTful API as any other API:

POST /employees HTTP/1.1 
[{"departmentId": 10, "departmentName": "IT"}, 
{"departmentId": 20, "departmentName": "HR"},...] 

The asynchronous API that is responsible for handling the preceding request accepts the request and returns the 202 Accepted status to the caller without keeping the caller waiting for the request to finish. The response also can have a temporary resource inside the Location header, which can be used by the client to query the status of the process. Here is an example of the response generated by the server:

HTTP/1.1 202 Accepted 
Location: /queue/job1234

The JAX-RS 2.0 specification allows you to build asynchronous...