Recently I've been working on building a REST API using Sails.js I identified the resources I need for my app and what I observed (IMO) is that the majority of frameworks (built on top of Express) are very effective when it comes to manipulating a single resource.
Also, I found that in majority of requests, I needed to manipulate more than a resource. So for example let's say that we have the following structure and the links between resources:
Users -- user's metadata
`- Books -- book metadata
`- author
`- Gallery -- Images -- image metadata
`- Videos -- video metadata
The resources from above are: Users
, Books
, Gallery
, Images
and Videos
. Every resource will store only id's of it's subresources.
The problem I encountered in almost all cases was when I inserted a new subresource. After inserting a book then I would find it's owner and add a reference to this book.
Things gets worse when I upload an image. In this case after creating an Image, by knowing the user who uploaded the image, I create a gallery, push the image reference in gallery and assign the gallery's id to that user.
The problem here is that I need to to this from the users controller, or from images controller or whatever controller and manipulate all the resources. Like this, the code repetition gets higher and things becomes mixed and ugly (having for example calls to Users model from Images controller or Gallery controller).
Of course the simplest way would be to get rid of the Gallery subResource and add the videos and photos right to the user. But this was just an example.
So I would like to structure my app by having those 4 separate modules (Users, Gallery ...) which will provide their API (even if it's a basic one, i.e. CRUD). Then dispatch the routed request to the appropriate controller/handler which will interact with my modules and manipulate them. Also, when the request implies a single resource, I would like to automatically dispatch to module's handler (shortcutting the controller/handler).
Is this a good pattern for scaling a REST API (although this has nothing to do with the REST, but with data manipulation)?
If so, is there any library or even Express that I can use to create the modules? I use mongoDb with mongoosejs for models.
Can you recommend me a file structure for the app?
I also tagged golang
to this question because I'm interested in finding is there any framework that would fit my needs (maybe beego, martini or goweb).
I don't intend to ask an opiniated question, but I rather hope that someone already have some experience with this and I'm tired of googling for a solution, all the results I'm gettint are how to build a basic rest api with I don't know what framework and doesn't really address the architecture/scalability of obtaining a heavy app production ready.
Thanks.