Search code examples
resthttp-verbs

Proper REST endpoints when requesting reprocessing of failed asynchronous task


Imagine a system for requesting files are upload from a particular URL.

http://example.com/{accountId}/files

A POST is made to that endpoint to initiate the file transfer. But given that the file can be large, and the process may take a while the server returns a 202 response.

After some time a GET is performed to

http://example.com/{accountId}/files/{fileId}

If the returned status of that file is still pending then we want to tell the server to attempt the transfer again, as we consider it timed out.

What I am stumped by is what the appropriate REST endpoint/HTTP verb would be to trigger the server to reprocess that file.


Solution

  • I would suggest adding a "processor" resource that contains the status of the image processor:

    http://example.com/{accountId}/files/{fileId}/processor
    

    A GET on that could return JSON like this:

    {
      "status": "Pending"
    }
    

    Clients could then restart the processor by issuing an empty POST to the processor resource. Further more the client could POST JSON with a "reason" value to be logged by the server (instead of just issuing an empty POST).

    The base resource /{accountId}/files/{fileId} could include a link to the processor resource such that the client won't have to be hard coded with that information.