Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Cancel a REST api request?

Tags:

java

rest

I use REST API based system, in which there are some requests that take long time to complete. I want to give user an option to cancel the request.

like image 526
Anirudh Jadhav Avatar asked Aug 05 '15 12:08

Anirudh Jadhav


1 Answers

First, support

POST /requests

which will return a reference to the status of the request

{
    "id": 1234,
    "self"": "/requests/1234"
    "status": "Running"
}

Then add support for

PUT /requests/1234
{
    "status": "Canceled:"
}

That will let clients cancel a request if it hasn't finished yet. If the request is to create some other kind of resource, then instead of POST /requests, do POST /myResource, but still return the status object with the pointer to /requests in the response.

Clients can then poll /requests to see when the request is complete.

like image 176
Eric Stein Avatar answered Sep 18 '22 20:09

Eric Stein