The 425 "Too Early" status code's description:
Indicates that the server is unwilling to risk processing a request that might be replayed
How is it used in a real world scenario? Examples would be appreciated.
The 425 "Too Early" status code's description:
Indicates that the server is unwilling to risk processing a request that might be replayed
How is it used in a real world scenario? Examples would be appreciated.
You can use a 425 as an error code to handle idempotent requests.
Real world example: I want a request to my API to send money to someone through some crusty unreliable old banks api. Like 60% of the time the underlying api is fast enough, but 40% of the time clients will time out while waiting. If they retry after a timeout the request could potentially double bill them.
So in my API, I ask the sender to send a transactionId
, then when they retry the request, they would resend the same transactionId
. On my apis side I'm going to store that transactionId
and then start the (potentially long running) money transfer. When the transfer finishes you save the result to the transactionId
and then return 200(transferResult)
to the sender.
If the client gets impatient and retries then the next web request will see that that transactionId
is still in flight and return a 425 Too Early. They can then wait a few seconds and try again getting more 425 Too Early responses until the transfer finishes and you return the 200(transferResult)
to the sender.
I know this answer is 6 months late, but maybe that helps understand what a 425 can be used for.
Use HTTP status codes for their intended use, don't invent your own uses. Both scenarios explained here by other answers would benefit from using more fitting status codes (like 429 which includes a handy header retry-after).
The 425 status code is for a very specific scenario, namely:
Early-Data: 1
headerThat's it. That's what it's for. Don't use it for anything else.
https://www.rfc-editor.org/rfc/rfc8446#section-4.2.10, https://datatracker.ietf.org/doc/html/rfc8470#section-1
I use 425 when response is calculated on demand (i.e. the first request), but it may take potentially long to calculate it.
E.g. some reports or metadata can be handled like this.
So after a request to particular resource comes for first time - it gets 425 and a special job is queued for background workers to proceed. Once calculation is finished - further requests to the same resource return 200.
© 2022 - 2024 — McMap. All rights reserved.