P
P
Pavel Lysenko2016-09-29 13:06:28
Node.js
Pavel Lysenko, 2016-09-29 13:06:28

How to change the processing status of a REST request via WebSockets?

There is an AngularJS SPA that works with a NodeJS server via a REST API.
I would like to teach it to receive changes in the status of processing REST requests from the server, because some of them take quite a long time.
An example of changes in the processing status of a REST request.

  1. Request has been sent
  2. Request received
  3. Getting data from DB 1
  4. Getting data from DB 2
  5. data link
  6. Preparing a response

This seems to fit perfectly with WebSockets, but the further into the forest, the fatter the wolves.
It's not clear how to tie REST requests to the specific client that opened the socket connection.
Maintain a dictionary of matching client id and socket session number? Then the dictionary will grow uncontrollably when reconnected, which smells like a memory leak.
Or even change REST to sockets? Then it will be necessary to do all caching by handles.
Wherever you throw - everywhere a wedge.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Matvey Safronov, 2016-09-29
@impeee

In RESTful, there is such a practice: to return as a response to the user not data, but the status 202 Accepted along with a link by which the client itself monitors the state of the process, i.e. the same http requests. Link something like this: /resource/id, id must always be unique, without collisions. You need to create a queuing mechanism on the server side.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question