ng2-rest 19.0.52 → 19.0.53

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,136 +1,136 @@
1
-
2
- ## ng2-rest ##
3
-
4
- Robust isomorphic REST framework for browser (Angular, React etc.) and backend (NodeJS) JavaScript/TypeScript apps.
5
-
6
- Features:
7
- - Compatible with Angular (2+) (newest 13,14 also...) , React, Vue , NodeJS (works everywhere)
8
- - Compatible with RxJS operators (exhaustMap, switchMap, request cancelation etc.)
9
- - Based on [axios](https://axios-http.com/) => excellent alternative to Angular's [HttpClient](https://angular.io/api/common/http/HttpClient)
10
- - JSONP api request handling
11
- - Transfer class instance from server to client and back
12
- - Elegant way of dealing with REST api ( *similar to ExpressJS routes definitions* )
13
-
14
- (more documentation soon... )
15
-
16
- To install this package run:
17
-
18
- npm install ng2-rest --save
19
-
20
- Import Resource class:
21
- ```ts
22
- import { Resource } from 'ng2-rest/browser';
23
- ```
24
-
25
- Resource
26
- ========
27
-
28
- Fit you existing API (not only REST) into new fluent objects with **Resource**
29
- class observables. Use power of **async** in new angular templates;
30
-
31
- **template.html**
32
- ```html
33
- Users:
34
- <ul *ngIf="model.allUsers() | async; else loader; let users" >
35
-
36
- <li *ngFor="let user of users">
37
- {{user.id}} {{user.fullName()}}
38
- <br>
39
- <input type="name" [(NgModel)]="user.name" >
40
- <button (click)="model.update(user)" > Update </button>
41
- </li>
42
-
43
- </ul>
44
-
45
- <ng-template #loader> loading users... </ng-template>
46
-
47
- ```
48
- **component.ts**
49
- ```ts
50
- class User {
51
- name: string;
52
- surname: string;
53
- id: number;
54
-
55
- fullName() {
56
- return `Surname: ${this.surname}, Name: ${this.name}`;
57
- }
58
- }
59
-
60
- // Express.js style url endpoint model
61
- // you can ommit "<User>" part is you don't wanna see response interface
62
- // also you can ommit third argument ",User" is you don't wanna
63
- // map response object to User class objects
64
- const rest = Resource.create<User>("http://yourbackend.com/api","users/:id",{'':User} )
65
-
66
- class UserComponent {
67
-
68
- // Prepare your beautiful interface
69
- model = {
70
- allUsers: () => rest.model()
71
- .array
72
- .get()
73
- .observable // Observable resposne (useful for Angular 2+ html templates)
74
- .pipe( map({ body } => body.json) ) // get all users, body.json => User[]
75
-
76
- userBy: (id) => rest.model({id})
77
- .get() // Promise response by default
78
- .then({ body } => console.log(body.json)) // get user by id, body.json => User
79
-
80
- update: async (user:User) =>{
81
- try {
82
- await rest.model({id:user.id}).put(user) // Promise response by default
83
-
84
- alert('Update sucess')
85
- } catch(e) {
86
- alert(e)
87
- }
88
- }
89
- }
90
-
91
- constructor() { }
92
-
93
- }
94
- ```
95
-
96
- Specification
97
- ============
98
- Example **UrlParams[]** :
99
- `[ { sort: true },{ filter: 'id,5' }, { filter: 'name,test' } ]`
100
-
101
-
102
- | Name | Parameters | Description |
103
- | :---: | --- | ---: |
104
- | **array** | changes response type to array |
105
- | **get** | `model, UrlParams[] ` | get data |
106
- | **post** | `model, UrlParams[] ` | create data |
107
- | **patch** | `model, UrlParams[] ` | change data <br>(effect of changing data may be diffrent with each request) |
108
- | **put** | `model, UrlParams[]` | change data <br>(can be done multiple times with same effect) |
109
- | **head** | `model, UrlParams[]` | check data |
110
- | **delete** | `model, UrlParams[] ` | remove data |
111
- | **jsonp** | `model, UrlParams[] ` | get jsonp data |
112
-
113
-
114
-
115
- # Production mode
116
- ===
117
- Nice things to do in production mode:
118
-
119
- **1. Disable warnings.**
120
-
121
- If you don't wanna see warning, disable it like this:
122
- ```ts
123
- if (environment.production) {
124
- Resource.enableWarnings = false;
125
- }
126
- ```
127
-
128
- # Angular 2+ ngZone
129
- If you are using Angular 2+ you need to do this in your root **app.component**:
130
- ```ts
131
- constructor(zone:NgZone) {
132
- Resource.initAngularNgZone(zone)
133
- }
134
- ```
135
-
136
-
1
+
2
+ ## ng2-rest ##
3
+
4
+ Robust isomorphic REST framework for browser (Angular, React etc.) and backend (NodeJS) JavaScript/TypeScript apps.
5
+
6
+ Features:
7
+ - Compatible with Angular (2+) (newest 13,14 also...) , React, Vue , NodeJS (works everywhere)
8
+ - Compatible with RxJS operators (exhaustMap, switchMap, request cancelation etc.)
9
+ - Based on [axios](https://axios-http.com/) => excellent alternative to Angular's [HttpClient](https://angular.io/api/common/http/HttpClient)
10
+ - JSONP api request handling
11
+ - Transfer class instance from server to client and back
12
+ - Elegant way of dealing with REST api ( *similar to ExpressJS routes definitions* )
13
+
14
+ (more documentation soon... )
15
+
16
+ To install this package run:
17
+
18
+ npm install ng2-rest --save
19
+
20
+ Import Resource class:
21
+ ```ts
22
+ import { Resource } from 'ng2-rest/browser';
23
+ ```
24
+
25
+ Resource
26
+ ========
27
+
28
+ Fit you existing API (not only REST) into new fluent objects with **Resource**
29
+ class observables. Use power of **async** in new angular templates;
30
+
31
+ **template.html**
32
+ ```html
33
+ Users:
34
+ <ul *ngIf="model.allUsers() | async; else loader; let users" >
35
+
36
+ <li *ngFor="let user of users">
37
+ {{user.id}} {{user.fullName()}}
38
+ <br>
39
+ <input type="name" [(NgModel)]="user.name" >
40
+ <button (click)="model.update(user)" > Update </button>
41
+ </li>
42
+
43
+ </ul>
44
+
45
+ <ng-template #loader> loading users... </ng-template>
46
+
47
+ ```
48
+ **component.ts**
49
+ ```ts
50
+ class User {
51
+ name: string;
52
+ surname: string;
53
+ id: number;
54
+
55
+ fullName() {
56
+ return `Surname: ${this.surname}, Name: ${this.name}`;
57
+ }
58
+ }
59
+
60
+ // Express.js style url endpoint model
61
+ // you can ommit "<User>" part is you don't wanna see response interface
62
+ // also you can ommit third argument ",User" is you don't wanna
63
+ // map response object to User class objects
64
+ const rest = Resource.create<User>("http://yourbackend.com/api","users/:id",{'':User} )
65
+
66
+ class UserComponent {
67
+
68
+ // Prepare your beautiful interface
69
+ model = {
70
+ allUsers: () => rest.model()
71
+ .array
72
+ .get()
73
+ .observable // Observable resposne (useful for Angular 2+ html templates)
74
+ .pipe( map({ body } => body.json) ) // get all users, body.json => User[]
75
+
76
+ userBy: (id) => rest.model({id})
77
+ .get() // Promise response by default
78
+ .then({ body } => console.log(body.json)) // get user by id, body.json => User
79
+
80
+ update: async (user:User) =>{
81
+ try {
82
+ await rest.model({id:user.id}).put(user) // Promise response by default
83
+
84
+ alert('Update sucess')
85
+ } catch(e) {
86
+ alert(e)
87
+ }
88
+ }
89
+ }
90
+
91
+ constructor() { }
92
+
93
+ }
94
+ ```
95
+
96
+ Specification
97
+ ============
98
+ Example **UrlParams[]** :
99
+ `[ { sort: true },{ filter: 'id,5' }, { filter: 'name,test' } ]`
100
+
101
+
102
+ | Name | Parameters | Description |
103
+ | :---: | --- | ---: |
104
+ | **array** | changes response type to array |
105
+ | **get** | `model, UrlParams[] ` | get data |
106
+ | **post** | `model, UrlParams[] ` | create data |
107
+ | **patch** | `model, UrlParams[] ` | change data <br>(effect of changing data may be diffrent with each request) |
108
+ | **put** | `model, UrlParams[]` | change data <br>(can be done multiple times with same effect) |
109
+ | **head** | `model, UrlParams[]` | check data |
110
+ | **delete** | `model, UrlParams[] ` | remove data |
111
+ | **jsonp** | `model, UrlParams[] ` | get jsonp data |
112
+
113
+
114
+
115
+ # Production mode
116
+ ===
117
+ Nice things to do in production mode:
118
+
119
+ **1. Disable warnings.**
120
+
121
+ If you don't wanna see warning, disable it like this:
122
+ ```ts
123
+ if (environment.production) {
124
+ Resource.enableWarnings = false;
125
+ }
126
+ ```
127
+
128
+ # Angular 2+ ngZone
129
+ If you are using Angular 2+ you need to do this in your root **app.component**:
130
+ ```ts
131
+ constructor(zone:NgZone) {
132
+ Resource.initAngularNgZone(zone)
133
+ }
134
+ ```
135
+
136
+
package/browser/README.md CHANGED
@@ -1,24 +1,24 @@
1
- # MyLib
2
-
3
- This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.2.0.
4
-
5
- ## Code scaffolding
6
-
7
- Run `ng generate component component-name --project my-lib` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project my-lib`.
8
- > Note: Don't forget to add `--project my-lib` or else it will be added to the default project in your `angular.json` file.
9
-
10
- ## Build
11
-
12
- Run `ng build my-lib` to build the project. The build artifacts will be stored in the `dist/` directory.
13
-
14
- ## Publishing
15
-
16
- After building your library with `ng build my-lib`, go to the dist folder `cd dist/my-lib` and run `npm publish`.
17
-
18
- ## Running unit tests
19
-
20
- Run `ng test my-lib` to execute the unit tests via [Karma](https://karma-runner.github.io).
21
-
22
- ## Further help
23
-
24
- To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
1
+ # MyLib
2
+
3
+ This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 13.2.0.
4
+
5
+ ## Code scaffolding
6
+
7
+ Run `ng generate component component-name --project my-lib` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project my-lib`.
8
+ > Note: Don't forget to add `--project my-lib` or else it will be added to the default project in your `angular.json` file.
9
+
10
+ ## Build
11
+
12
+ Run `ng build my-lib` to build the project. The build artifacts will be stored in the `dist/` directory.
13
+
14
+ ## Publishing
15
+
16
+ After building your library with `ng build my-lib`, go to the dist folder `cd dist/my-lib` and run `npm publish`.
17
+
18
+ ## Running unit tests
19
+
20
+ Run `ng test my-lib` to execute the unit tests via [Karma](https://karma-runner.github.io).
21
+
22
+ ## Further help
23
+
24
+ To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.