简体   繁体   中英

What http code should I return when the request is rejected while process is running?

I have a REST api that launch a heavy calculation on the serveur (it tikes a few seconds). For that I'm returning 202 (ACCEPTED) http code to the client, which will not expect a returning value. Ok so far.

What will I return for another client how calls this url while the process (launched by the first call) is not terminated ?

This second call will not be processed, it will be ignored and the client must try again later .

If you insist on the current behavior, then you'll return 503 . This tells the (standard compliant) client that your server is temporarily overloaded, and it can retry later (you can even hint when it can on Retry-After header. While standard-compliant, you'll only want to do this if queuing the process requested by the second call later is impossible, perhaps because the internal state will have changed so the second call is invalid. If it's possible to just queue the process with an identical result as when the client manually retry the call, then just return 202.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM