My new application main collection is still very basic:
var TransactionCollection = Backbone.Collection.extend({
model: Transaction,
url: '/api/transactions'
});
This is good while developing, but now I'd like to add some pagination and filtering features.
I'm not sure about what URL schema I should use. I mean:
- page 1, all transactions, January 2014 => /api/transactions/2014/01
- page 2, all transactions, January 2014 => /api/transactions/2014/01?p=2
- page 1, all transactions, February 2014 => /api/transactions/2014/02
- page 1, only incomes, June 2014 => /api/transactions/incomes/2014/06
- page 2, only outcomes, June 2014 => /api/transactions/outcomes/2014/06/?p=2
Is it a good structure, in your opinion?
In each case, what's the best practice for managing such a collection? I guess I can make the url: property a function, to dynamically handle several parameters (page, filter, period) passed to the collection before fetching it. Or is it better to pass parameters with each fetch?