Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST: how to tell server to do some background process

Tags:

rest

I am building a client-side product with REST. All user interaction will be done with a browser (the config stuff will be on a server running on localhost). I want everything to be REST compliant, even though the application will be running on a client's machine on localhost and will never be accessible from the outside.

The commands are pretty simple:

  • update
  • restart
  • sync

Here's what I've come up with:

  • POST to / with 'action' parameter (JSON) detailing specifics
  • PUT a new resource
    • subsequent GET requests will return the status
    • when the command is complete, the resource is deleted

What would be the most RESTful way to implement this?

Note:

I'm not asking for scrutinization of my software architecture. I have reasons for choosing a REST interface instead of a unix domain socket, CLI interface, or even a regular GUI interface. The justification would overcomplicate the question and make it too localized.

I have had the same need on a couple of different projects (both client only and server) and I am looking for community input on best practices.

like image 974
beatgammit Avatar asked Aug 13 '11 02:08

beatgammit


1 Answers

I would POST to a /process resource with the appropriate parameters necessary to start the process, then I would have it return a Location header to that resource that actually represents the process status (/process/123). You can then use GET on that process to get the latest information about it.

I would not automatically delete the process, because if you do that, the client will not know if the process finished properly or not, just simply that it finished (well, stopped running).

Noting that, the client can certainly DELETE the resource when it is done, or you can clean it up later after some reasonable time where whoever was interested in it is likely not to be any more.

like image 164
Will Hartung Avatar answered Sep 24 '22 19:09

Will Hartung