Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/agonbina/restier
https://github.com/agonbina/restier
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/agonbina/restier
- Owner: agonbina
- License: mit
- Created: 2015-02-23T09:02:18.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-02T14:01:31.000Z (almost 10 years ago)
- Last Synced: 2024-04-14T20:06:25.989Z (9 months ago)
- Language: JavaScript
- Size: 133 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RESTier
```js
var config = {
host: '',
namespace: '/api/v0',
resources: {
rooms: {
path: '/rooms',
resources: {
keys: {
path: '/{id}/keys'
},
equipment: {
id: 'name',
path: '/{id}/equipment',
resources: {
specs: {
path: '/{id}/specs'
}
}
}
}
},
cars: {
namespace: '/api/v1',
path: '/cars',
resources: {
brands: {
path: '/brands'
}
}
}
}
}var store = new Store(config)
```### Manipulating resources
```js
var room = store.resource('rooms').id(5) // rooms/5room.retrieve().then(...)
room.set('name', 'Agon').save().then(...)
room.get('name') // 'Agon'var tvSpecs = store.resource('rooms').id(1)
.resource('equipment').id('tv')
.resource('specs') // rooms/1/equipment/tv/specs// NOT SO SURE: var tvSpecs = store.rooms().id(1).equipment().id('tv').specs()
// tvSpecs = room.resource('equipment').id('tv').resource('specs') is equivalenttvSpecs.retrieve().then(function(specs) {
console.log(specs)
})var roomKeys = store.resource('rooms').id(5).resource('keys') // rooms/5/keys
roomKeys.fetch().then(function(keys) {
// keys == [ ... ]
})var brands = store.resource('cars').resource('brands')
// brands instanceOf Collection === true
brands.fetch().then(function(list) {
// list == [ ... ]
})
```### Implementation
```js
Model.prototype = {
save:
load:
reload: // syntactic sugar, proxies call to .retrieve
delete:set:
get:
toJSON:resource:
}Collection.prototype = {
create:
fetch:
id:resource:
}
```