airbnb/rendr — pull request #52 by spikebrehm (2013-05-27 22:25:17+00:00)
Title: Multiple api hosts, part 2

This is a simplified take on #45.

In your API config passed to `DataAdapter` (for example; `DataAdapter` is left to the [application implementation](https://github.com/airbnb/rendr-app-template/blob/master/server/lib/data_adapter.js)), you can specify either a single or multiple API hosts:

### Single API host
```js
// config/development.js
api: {
host: 'api.github.com',
protocol: 'https'
}
```

### Multiple API hosts
```js
// config/development.js
api: {
"default": {
host: 'api.github.com',
protocol: 'https'
},
"travis-ci": {
host: 'api.travis-ci.org',
protocol: 'https'
}
}
```

Then, in models, you can use the `api` property specify which API to use, or leave it blank to use default. The URL structure for proxying API requests through the Rendr server has changed a bit to allow specifying metadata about the request:

### Using default API
```js
// app/models/user.js
module.export = BaseModel.extend({
url: '/users/:id'
});
```
```js
// somewhere in fake code, run in the browser.
var myUser = new User({id: 42}, {app: app});
myUser.fetch();
```
This would send a request to the Rendr server:

/api/-/users/42

which in turn sends out the request to the API:

https://api.github.com/users/42

### Specifying an API
```js
// app/models/user.js
module.export = BaseModel.extend({
url: '/users/:id',

// corresponds to keys in API config
api: 'travis-ci'
});
```
```js
// somewhere in fake code, run in the browser.
var myUser = new User({id: 42}, {app: app});
myUser.fetch();
```
This would send a request to the Rendr server:

/api/travis-ci/-/users/42

which in turn sends out the request to the API:

https://api.travis-ci.org/users/42