i am looking for advice and suggestions on best practices when working with WebAPI 2:
Lets say i have two controllers(users and books), and that would like to accept these routes:
/users/{user_id}/books <= books owned by user_id
/books <= all books
/books/{book_id} <= book from id
What would be the best practice on dealing with the /users/{user_id}/books specifically? I am dealing with a lot of custom routes in a REST API, so i use [RoutePrefix] and [Verb, Route] on methods.
Thanks a lot in advance! I am always trying to find better solutions and practices to common situations.
I like to put all my routes for the returned entity on the same controller. So a BooksController would look like this:
Now any route that returns Books should be on this controller. Any route that returns Users would be placed on the UsersController. This has helped us keep things organized and simplified since a Route attribute can be placed on any controller, you can very easily have any route defined on any controller that makes it difficult track down all the possible routes.