C
C#3mo ago
Alex

API Routes structure

Hello! I have user, user can have many favorite stations. User can add/remove station from favorites. What controller should I put these functionalities Users or Stations e.g. POST:/users/{id}/stations/favorite, body stationId or POST:/stations/favorite/{stationId}, body:userId?
5 Replies
Pobiega
Pobiega3mo ago
Is the user logged in? Can they reasonably edit other users stations? I'd always prefer to read the userID from the currently logged in user, if thats an option. Means you dont open yourself up to someone inspecting the http calls and making their own
Alex
Alex3mo ago
yes, user = user account, they log in with email and password and have session stored in refresh + jwt, user can't see other users favorite stations. Station data can't be changed.
Pobiega
Pobiega3mo ago
alr, then you dont need to take userId at all just read it from the currently authenticated user
Alex
Alex3mo ago
where is better place for these routes? UserController or StationController?
Pobiega
Pobiega3mo ago
I'd go with stationcontroller