I work with internal AngularJS SPA, based on REST API and problem is some REST requests proceeds for very a long time (~5-10 seconds).
It is ridiciolus, but there is nothing to do with it – server need to get a lot of data from different sources and math it together before response.
Nice solution is to show request status to user, and here we come to the WebSockets.
Example of request status showing to user
It is better to provide both things, REST and Websocket, so web pages can use the websocket and automated clients with no websocket support and still use the API. You can process those request asynchronously, and use the REST async pattern.
HTTP 202 Acceptedwith a
Locationheader to a queue endpoint
/queue/<taskid>that provides the status of the task.
Locationheader in a regular basis.
HTTP 202 Accepted.
HTTP 303 See Otherwith a
Locationheader that redirects the client to the location of the processing result.
Locationheader, or just provide only the task id in another header.