1 year ago

Best API approach for non-resource

Posted 1 year ago by BillRiess

I'm curious what the general consensus is here as to the best approach for a non-resource API. I'm currently building a RESTful API using passport and everything is working great for my standard resources but I have a few things that don't exactly fit that scope. For example, one API call may be a timer which would have 2 endpoints start and stop. The start requires 2 additional parameters to be passed (things to be tracked by the timer) while the stop would just stop the active timer for that user. A user will only ever have 1 timer active at a time so no need to pass timerId.

Different ways to approach this:

GET: /api/v1/timer/start/{thing1ID}/{thing2ID}
GET: /api/v1/timer/start?thing1=123&thing2=abc
POST: /api/v1/timer/start
Form-body: [thing1 => <id>, thing2 => <id>]

The stop endpoint would just need to be called to end the timer, this could be through any of the http verbs.

I'm just looking for some general feedback here as to what would be the best approach for something like this.

Please sign in or create an account to participate in this conversation.