Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are asynchronous RESTful web services possible?

Reading RESTful documentation, it does not seem like it is possible to implement an asynchronous instance, but someone may know better on SO.

What I mean here is I would like to execute service requests asynchronously:

@Path("/helloworld", asyncSupported=true)
public class MyHelloWorldService {
    ...
}

I know asyncSupported is not defined in @Path, but I am looking for something similar to @WebServlet. Then, I would like to use AsyncContext instances (or anything equivalent).

Is this possible?

like image 570
Jérôme Verstrynge Avatar asked Sep 28 '11 12:09

Jérôme Verstrynge


People also ask

Can Web services be asynchronous?

The asynchronous web services receives the request, sends a confirmation message to the initiating client, and starts process the request. Once processing of the request is complete, the asynchronous web service acts as a client to send the response back to the callback service.

Is REST API sync or async?

Although REST proved to be much easier to implement than other comms (notably the XML-based SOAP), it has an inherent disadvantage in that it is synchronous in nature, rather than asynchronous. “A client sends a request, the server sends a response,” Roper said, describing how REST works.

What is asynchronous request and response in restful web services?

By asynchronous, I mean that the client will make the request and continue with its execution with out waiting for the response from the service.Is it possible to achieve this? I need to deploy the service in WebSphere Application Server. web-services rest asynchronous.


1 Answers

RestEasy has some support1 for it - using a custom annotation called @Suspend.

See here: http://docs.jboss.org/resteasy/docs/2.2.1.GA/userguide/html/Asynchronous_HTTP_Request_Processing.html

There is also a framework/library on top of Jersey called Atmosphere however that might be overkill for your usecase as its focus appears to be on long-polling client/server web applications ( e.g. chats - https://github.com/Atmosphere/atmosphere )

[1] The CDI scope for your request will be lost in in the thread that actually executes the logic. See the RESTEasy-682 issue for more information. This is a problem that hasn't been solved by any REST frameworks that I know of at this moment[March 2014].

like image 86
Eike D Avatar answered Sep 27 '22 23:09

Eike D