AmpersandJS / ampersand-model

Observable objects, for managing state in applications.
MIT License
84 stars 31 forks source link

Mixing in data for every request #65

Open ghost opened 8 years ago

ghost commented 8 years ago

Hi There,

I have some data relating to authorization that needs to be included in every ajax request. How would I include this in a base class without having to include it in every single one of my models.

For example:

client_id: 'myAppId'

should be part of every ajax request.

I had a look at ajaxConfig .. but this only lets me set headers and and xhr options, but does not seem to provide a way to include data.

I also looked at the "request" module on npm, but even there I couldn't find a neat way to always inject some data into every request.

In AngularJS I saw an example of an "authentication injector service" ... how would I achieve this with Ampersand?

Thanks,

Oliver

wraithgar commented 8 years ago

Altering the data of a model before going to and after coming from the server is typically handled by serialize and parse, respectively. Would this work for your case?