What is the default behavior of REST web services - synchronous or asynchronous?
If it's synchronous then can we create asynchronous?

- 16,038
- 10
- 74
- 104

- 957
- 1
- 8
- 24
5 Answers
"Synchronous" or "Asynchronous" is the behaviour of the client that is requesting the resource. It has nothing to do with REST webservice, its structure, or the supporting server.
Synchronous behaviour:
- Client constructs an HTTP structure, sends over the socket connection.
- Waits for the response HTTP.
Asychronous behaviour:
- Client constructs HTTP structure, sends the request, and moves on.
- There's another thread that is waiting on the socket for the response. Once response arrives, the original sender is notified (usually, using a callback like structure).

- 9,110
- 5
- 50
- 65

- 43,308
- 12
- 81
- 104
-
12You could argue that a HTTP service that returns a 202 is providing an asynchronous service, whereas one that returns 200/201 is synchronous. – Darrel Miller Apr 17 '13 at 19:08
-
3@DarrelMiller Nice point. A service returning 202 merely triggers/spawns off another process and returns immediately with (quoting the RFC) *some kind of pointer to the status monitor*. This doesn't mean the server has a *persistent connection to client, and notifies it when the process is done*. The client has to poll the "pointer"; or a library can be built over it in an async way. (I read the RFC again to be sure, correct if I'm wrong). Also, it still doesn't make the "default" behavior of REST services to be Async – UltraInstinct Apr 18 '13 at 04:28
-
So we use http (Which is a synchronous protocol) to implement the REST structure/service ? Doesn't that make the REST service a synchronous one ? – prime Aug 15 '18 at 06:55
@Thrustmaster has explained it well. I just wanted to add a point to make it sound simpler.
REST web service is nothing but an HTTP call. You make a HTTP request to a URL and get a HTTP response back. How to handle the request and response is up to the caller.

- 16,038
- 10
- 74
- 104

- 4,766
- 5
- 23
- 43
REST services has not nothing to do with being Synchronous or asynchronous.
Client Side: Clients calling must support asynchronous to achieve it like AJAX in browser.
Server Side: Multi- Thread environment / Non blocking IO are used to achieve asynchronous service.

- 8,171
- 3
- 26
- 47
I think this might be a good help for you to understand the RESTful web services in Java:
You can control the client being synchronous or asynchronous from the client side. An example - using AJAX.

- 16,038
- 10
- 74
- 104

- 18,094
- 55
- 145
- 232
Yes you can have Asynchronous as well as Synchronous Web Service. You can use any of the frameworks like Restlet, JAXB, JAX-RS.

- 878
- 1
- 8
- 21