https://github.com/gera2ld/restful-ng
RESTful service for Angular 1.x
https://github.com/gera2ld/restful-ng
Last synced: 12 months ago
JSON representation
RESTful service for Angular 1.x
- Host: GitHub
- URL: https://github.com/gera2ld/restful-ng
- Owner: gera2ld
- Created: 2016-04-20T05:37:31.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-01-22T08:47:00.000Z (over 9 years ago)
- Last Synced: 2024-05-02T20:35:19.516Z (about 2 years ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# restful-ng



This is a RESTful service for Angular 1.x.
APIs are consistent with [restful-fetch](https://github.com/gera2ld/restful-fetch).
Installation
---
``` sh
$ bower install restful-ng
# Or
$ npm install restful-ng
```
Usage
---
``` js
angular.module('app', ['restful-ng'])
.config([
'RestfulNgProvider',
function (RestfulProvider) {
RestfulProvider.config({
root: '/api',
});
}
])
.run([
'RestfulNg',
function (RestfulNg) {
RestfulNg.get('/hello').then(function (data) {
console.log(data);
});
// Models
var myCar = RestfulNg.model('cars/1');
// Interceptors
myCar.posthandlers.push(function (data) {
data.intercepted = true;
return data;
});
myCar.get().then(function (data) {
console.log(data);
});
// Submodels
var licence = myCar.model('licence');
// Placeholders
var seats = myCar.model('seats', ':seatId');
seats.posthandlers.push(function () {
console.log('Got a seat');
});
var seat1 = seats.fill({seatId: 1});
seat1.get().then(function (data) {
console.log(data);
});
// Override global interceptors
licence.overrides.posthandlers = [function (res) {
return res.data;
}];
licence.get().then(function (text) {
console.log(text);
});
}
]);
```
For more details, see documents of [restful-fetch](https://github.com/gera2ld/restful-fetch).