javarestschedule

RESTful trigger function


I have java restful service with a functionality that runs on a schedule. I want to implement a way to run that functionality on demand. what would be the proper/most effective way to achieve this?


Solution

  • So I'm hesitant as to what method to use and if there's any other way to achieve this without cheating the REST architecture.

    "It is okay to use POST." (Fielding, 2009)

    Analog: if you were building a boring website, then you would present the operator with a web form, with a "submit" button that would send a request to the web server. You probably wouldn't want the form submitted preemptively, so you would set the form method to POST so that general purpose components would understand that the semantics of the form are not "safe".

    That said, you could instead design the interaction using the metaphor of passing a new document to the server to store, where the storage of that document would trigger the side effects that you want. In other words, instead of a resource to which you post messages, which are then processed using the semantics unique to that resource, you could instead treat the message itself as a resource, and use remote authoring semantics (PUT/DELETE/PATCH) to deliver that information to the server.

    Both options are fine, as far as REST is concerned.

    That fact that the messages themselves have no explicit "state" really isn't important at all, from a REST perspective.