Skip to Content
RESTful Rails Development
book

RESTful Rails Development

by Silvia Puglisi
October 2015
Intermediate to advanced
350 pages
7h 26m
English
O'Reilly Media, Inc.
Content preview from RESTful Rails Development

Chapter 6. Asynchronous REST

Asynchronous operations might be one of the most complex aspects of RESTful architecture. Imagine performing a certain action on a resource that will take a considerable amount of time to finish. Should you leave the client to wait until the action has finished and you are able to return a meaningful HTTP code? In this chapter we will see what the best strategy is in situations like this one, and what codes your API should return when you want to tell the client that you will perform the operation at later time.

Asynchronous RESTful Operations

The HTTP protocol is synchronous. When an HTTP request is made to a server, the client expects an answer, whether it indicates success or failure (see Figure 6-1).

Figure 6-1. A simple REST request and response—the client has performed a POST request to a resource and the server has returned the 201 (Created) status code

Yet the fact that the server has returned an answer does not mean, per se, that the action or actions initiated by the request have to finish immediately. For example, you might request an operation that requires some time or resources to complete, and these might not be available at the moment the request is made.

This could very well be the case for a service that processes images or videos or audio files. In such a situation, the server usually accepts the request made by the client and agrees ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learn Rails 6: Accelerated Web Development with Ruby on Rails

Learn Rails 6: Accelerated Web Development with Ruby on Rails

Adam Notodikromo
Learning Rails 5

Learning Rails 5

J. Mark Locklear, Eric J Gruber, Barnabas Bulpett
Beginning Rails 6: From Novice to Professional

Beginning Rails 6: From Novice to Professional

Brady Somerville, Adam Gamble, Cloves Carneiro Jr., Rida Al Barazi

Publisher Resources

ISBN: 9781491910849Errata Page