restapihttprestful-architecture

Action in a REST API


The web service for my app is an Express server that I'm trying to keep as RESTful as possible.

I have a /timesheets route. Here a GET request obviously fetches a list of timesheets. Also, POST naturally creates a timesheet.

I need to, however, send an instruction to my web service to "sign off" on a set of timesheets for a certain paycycle (again another resource).

Providing sign-off for a set of timesheets in a paycycle isn't a resource, but an action, in my opinion. What would be the suggested best practice way for me to structure my web service?


Solution

  • Instead of thinking about 'signing off' as an action, you can rephrase this by thinking of 'being signed off' as a state. REST deals with transferring state, so this suddenly becomes easier.

    So if some resource looks like this (using JSON because it's what everyone does):

    {
      "signedOff" : false
    }
    

    Then the implication is that you can send a PUT request that sets this to:

    {
      "signedOff" : true
    }