Thursday 5 November 2020

How to return 202 Accepted and then continue processing the request in Nest.js

I need a controller action that:

  1. Authorizes the call
  2. Validates it
  3. Returns the 202 Accepted status
  4. Continues processing the request
  5. Makes a call to external API with the results of previously accepted and now processed request.

First two points are easy, I use AuthGuard then class-validator. But I don't know how to return the HTTP response then continue with processing.

As the request consists of an array of (possibly long-running) tasks I thought of using interceptor that uses RxJS to observes the status of tasks and calls external PI upon their completion. However, I have no experience with using RxJS or interceptors (not this way) so I'd really don't know how to leave interceptor's process running but immediately pass control to controller's action.

Also, perhaps there is another, better way? No interceptor but just put all the flow logic in the controller? Some other option?



from How to return 202 Accepted and then continue processing the request in Nest.js

No comments:

Post a Comment