C
C#8mo 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
Pobiega8mo 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
AlexOP8mo 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
Pobiega8mo ago
alr, then you dont need to take userId at all just read it from the currently authenticated user
Alex
AlexOP8mo ago
where is better place for these routes? UserController or StationController?
Pobiega
Pobiega8mo ago
I'd go with stationcontroller
Want results from more Discord servers?
Add your server