As a mini-project I'm attempting to reverse engineer the very forum on which you're reading this message. (I know there are series on this, but I'm doing it on my own at this point without referencing a step by step guide: just using the goal I see in front of me (though being honest I have peeked at the schema on jeff's lets build a forum github page)).
Jeff has used web routes for the vast majority of things, rather than ajax. So I have a RepliesController that handles all the crud type web routes.
The first place where he's using ajax I am coming across, that I want to go with, is to toggle the thumbs up mark to mark a question as helpful.
I have a controller for Replies, which contains store, update and destroy actions, and want to add toggleHelpful() and toggleBest(). toggleHelpful() is the one that really merits going in as an ajax request as stated above (for the thumbs up). Reason is its just a tiny thing so avoiding a page reload is a tiny bit nice and I'm happy to go with that.
Such a simple question really: is it OK to point an api route to a method in a controller that has mainly web routes in it? Looking at my past projects I've used separate API controllers, like 'API/LessonsApiController'.
My proposed position is: putting the toggleHelpful() method (returning json and using api auth) right in the RepliesController which has all my webroutes seems absolutely fine, as long as its clearly marked that it returns json, not html.
What differentiates the api route other than this is the middleware, but that's defined in the routes file, and it seems fine to put it in the same controller that serves the web routes, rather than create a new api controller for solely this purpose.
Does this sound OK? Any comments from experienced hands here on any aspect of this?
Thanks very much!