ng-s-resource
🏌🏽 Simplify RESTful http resource generator for Angular 4+
Quick look
UserService = this._res.create'/api/user/:id' // 1. define...this.api.UserService.get... // 2. usage/*Also can use `...UserService. post | put | head | patch | delete`*/
Install
yarn add ng-s-resource
or
npm i -S ng-s-resource
Configuration
_res.create(url, [options])
Name | Type | Explain |
---|---|---|
url | String |
Api url, and you can use api/user/:id , and use dynamic params { id: 2 } for replace it |
options[sub] | Object |
null |
options[sub].params | Object |
Resource params, like url params etc. |
options[sub].headers | Object |
Api headers, like { ...headers: { 'x-auth-token': '***' } } |
options[sub].data | Object |
Api data, just use in these methods post , put , patch |
options[sub].method | String |
Api method type, like get , head , delete , post , put , patch |
[sub] is your Service children name.
Example
Define
service/api.service.ts
Usage
pages/app.component.ts
...
Required things
app.module.ts
...
services/index.ts
Any problem?
Please let me know.
Is it useful?
License
MIT