Suppose I'm creating a REST API and my POST method creates a new Order. And I'd like to use Hypermedia in my API, supplying a list of available actions to the client, and path to a POST method should contain IdempotencyKey (so IdempotencyKey is created on the server, not on the client). For example:
{ // ..."actions": [ {"name": "createOrder","path": "/api/v1/orders/create/<idempotency-key-uuid>","method": "POST" } ]}How would you actually get this initial response if a user lands right on to the "Create Order" page? Should I issue some kind of get request when the page is initially loaded (to get the path of "createOrder" action)?
What happens when user clicks on "Create" button, so the POST request is issued, and then something bad happened (lost connection, timeout of some kind). The client does not get any response but the new Order is still created. The user refreshes the page to try again (to create Order). We should get the new IdempotencyKey if the order has been created, and the same IdempotencyKey if it hasn't, right? Is there any way to generate the same or the new IdempotencyKey on the server depending on what actually happened? Looks like it must depend on the state of the server, but I can't really figure out what the right implementation would be.