I am new to Backbone, NodeJS and web development and am struggling with the proper design of my Backbone Collection and Model GET
requests and routes on my NodeJS server.
At first I only used Models and specified the urlRoot
which worked perfectly. Once I added my Models to a Collection it used the Collections' url
parameter which was fine once I realized what was happening.
Say I have model "Book" and a collection "Library" defined as below:
Book
app.Book = Backbone.Model.extend({
defaults: {
title: 'No title',
author: 'Unknown'
}
});
Library
app.Library = Backbone.Collection.extend({
model: app.Book,
url: '/books'
});
Now if I do a GET
request on the model the url will be '/books/:id
which has a route specified on my node js server and I would return the book with the specified id.
My Question
I don't know what is good practice and design regarding the GET
request on the Collection. Say if I want to fetch a Collection of books by a certain author my url will look something like /books/:author_id
, but this would go to the same route as my Model GET
request on my node js server.
How do I distinguish between the Model GET
request and Collection GET
request on my node server? I don't want to use a quick hack, but would like design it properly.
What is considered best practice to pass 'filter' parameters with a Collection GET
request?