Skip to content

Commit

Permalink
Merge branch 'rest-adapter'
Browse files Browse the repository at this point in the history
  • Loading branch information
der-On committed Apr 8, 2015
2 parents 9b90e3e 23f2107 commit b7c285e
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 14,7 @@ NodeJS.
- [Defining Models](#defining-models)
- [Abbreviated syntax](#abbreviated-syntax)
- [Adapters](#adapters)
- [Using REST-Adapter in Browser](#using-rest-adapter-in-browser)
- [Datatypes](#datatypes)
- [Creating instances](#creating-instances)
- [Validations](#validations)
Expand Down Expand Up @@ -376,6 377,44 @@ myAdapter.addListener('error', function (err) {
});
```
#### Using REST-Adapter in Browser
You can use the REST-Adapter in the browser.
Assuming you use a tool like browserify to include `model` in your JS:
```javascript
var model = require('model');
var RestAdapter = require('model/lib/adapters/rest').Adapter;

model.defaultAdapter = new RestAdapter({
host: window.location.protocol '//' window.location.hostname ':' window.location.port '/',
defaultDataType: 'json',
defaultFormat: 'json',
crossDomain: false,
cacheLifetime: 5000,
camelize: true
});
```
You can then access the restApi and add filters as you need:
```javascript
var restApi = model.defaultAdapter.restApi;

// convert params to json
restApi.addFilter('param', rest.RestFilters.PARAM_FILTER_JSON);
```
After that you will also need to register all your models manually:
```javascript
var model = require('model');

model.register('User', require('app/models/user').User);
model.register('Event', require('app/models/event').Event);
```
## Creating instances
Creating an instance of one of these models is easy:
Expand Down Expand Up @@ -1263,4 1302,3 @@ Configure adapter options by creating a `test/db.json` file. See
- - -
Model JavaScript ORM copyright 2112 [email protected].

0 comments on commit b7c285e

Please sign in to comment.