C
C#4mo ago
stevie

How to organize API routes?

There is a .NET 6 WebApi with 2 controllers: PlatformsController and OrdersController. Now, in order to get orders, passing platformId is mandatory. /orders/{platformId} But ideally the api route would look like: /platforms/{platformId}/orders/{orderId}. But since orders must belong to platforms I'm forced to use 1 controller - PlatformsController. But in this case everything will have to be inside PlatformsController and swagger will show only one controller and won't be separated by orders for example. How to get around this?
1 Reply
Pobiega
Pobiega4mo ago
You can absolutely have an OrdersController with a route like /platforms/{platformId}/orders/{orderId} That said, you might find it cleaner to not use controllers at all for a structure like this and go with minimal endpoints or FastEndpoints instead, if you are feeling adventurous