DEV Community

Discussion on: Building Better REST APIs

Collapse
 
argherna profile image
Andy Gherna

It seems like in the section about Long-Running tasks, you're describing a pattern that would and could be better served by message queuing. This is great because long running tasks can happen in the background without forcing your customer to wait since this is asynchronous. My team uses the pattern:

  1. Receive the request.
  2. Gather any other data needed.
  3. Send the message to the message broker to be queued.
  4. API responds with a 202 - Accepted and a JSON body that contains a URL that a client can "poll" for status if necessary.

Meanwhile, the message is sent by the broker to a waiting "worker" that will process the message and perform any sort of updates needed to the application/service backing store to let anyone interested know that the work has been done.

Collapse
 
fidraj profile image
Yaro Fidra

Yes, I can recommend this practice too.