We have a FitnessClassesService
which allows scheduling fitness-training classes. There are a number of actors for every class:
- The main trainer who explains the entire workout - he does all the talking but does not necessarily do the workouts himself.
- A substitute trainer in case the main trainer is not available
- Two trainers who demonstrate the entire workout by actually doing it in the class - one for the newbies and one for old-timers
- Two trainers who just move around the class to clarify any doubts.
When a class is created, all the actors are also added to it. The trainers have an app from where they can see the classes which they have to participate in today (in any role).
I create classes by calling POST /classes
.
What would be the correct REST API for getting all classes for a trainer when they open their app. These are the alternatives I considered:
Get /classes
- Get userId from the HTTP header and use that to get classes for the current logged-in user only. However, this does not seem very RESTful to me.GET /classes/~alice
orGet /classes/current
- From designing-uri-for-current-logged-in-user-in-rest-applications . This will only get classes represented by the "current" user. However, unlike the example in the linked question where "users" was a resource and the "current" user represented a specific resource, I don't feel like "current" represents a resource for my usecase. "current" for me represents all classes where I am an interested party. This sounds like I have tofilter
on theclasses
resource instead of asking for a specific resource.GET /classes?actorId=alice
orGET /classes?actorId=current
- But what if someone callsGET /classes
. Should I verify that an actorId must always be passed. Additionally, the actorId must match the logged-in user's id. Is it okay to do such authorization based on URI parameters.Get /myclasses
- Use a different URI. This means that I will be creating classes byPOST /classes
but getting classes by a different URI.
What would be the canonical way of handling this.