ng2-rest 19.0.29 → 19.0.31
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 +135 -135
- package/browser/README.md +24 -24
- package/browser/fesm2022/ng2-rest.mjs.map +1 -1
- package/browser/package.json +1 -1
- package/index.js.map +1 -1
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/build-info._auto-generated_.js.map +1 -1
- package/lib/content-type.js.map +1 -1
- package/lib/cookie.js.map +1 -1
- package/lib/env/env.angular-node-app.js.map +1 -1
- package/lib/env/env.docs-webapp.js.map +1 -1
- package/lib/env/env.electron-app.js.map +1 -1
- package/lib/env/env.mobile-app.js.map +1 -1
- package/lib/env/env.npm-lib-and-cli-tool.js.map +1 -1
- package/lib/env/env.vscode-plugin.js.map +1 -1
- package/lib/env/index.js.map +1 -1
- package/lib/helpers.js.map +1 -1
- package/lib/index._auto-generated_.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/mapping.js.map +1 -1
- package/lib/models.js.map +1 -1
- package/lib/other/simple-resource.js.map +1 -1
- package/lib/params.js.map +1 -1
- package/lib/request-cache.js.map +1 -1
- package/lib/resource-service.js.map +1 -1
- package/lib/rest-headers.js.map +1 -1
- package/lib/rest-request.js.map +1 -1
- package/lib/rest.class.js.map +1 -1
- package/migrations/index.js.map +1 -1
- package/migrations/migrations_index._auto-generated_.js.map +1 -1
- package/package.json +1 -1
- package/tmp-environment.json +4 -4
- package/websql/README.md +24 -24
- package/websql/fesm2022/ng2-rest.mjs.map +1 -1
- package/websql/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,135 +1,135 @@
|
|
|
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.** | get,post,put,head,delete,jsonp | for everything, but with arrays |
|
|
105
|
-
| **get** | `UrlParams[] ` | get model by parameters |
|
|
106
|
-
| **post** | `model, UrlParams[] ` | post object model |
|
|
107
|
-
| **put** | `model, UrlParams[]` | put object model |
|
|
108
|
-
| **head** | `model, UrlParams[]` | get head for model |
|
|
109
|
-
| **delete** | `UrlParams[]` | remove object by params |
|
|
110
|
-
| **jsonp** | `UrlParams[]` | get jsonp data |
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
# Production mode
|
|
115
|
-
===
|
|
116
|
-
Nice things to do in production mode:
|
|
117
|
-
|
|
118
|
-
**1. Disable warnings.**
|
|
119
|
-
|
|
120
|
-
If you don't wanna see warning, disable it like this:
|
|
121
|
-
```ts
|
|
122
|
-
if (environment.production) {
|
|
123
|
-
Resource.enableWarnings = false;
|
|
124
|
-
}
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
# Angular 2+ ngZone
|
|
128
|
-
If you are using Angular 2+ you need to do this in your root **app.component**:
|
|
129
|
-
```ts
|
|
130
|
-
constructor(zone:NgZone) {
|
|
131
|
-
Resource.initAngularNgZone(zone)
|
|
132
|
-
}
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
|
|
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.** | get,post,put,head,delete,jsonp | for everything, but with arrays |
|
|
105
|
+
| **get** | `UrlParams[] ` | get model by parameters |
|
|
106
|
+
| **post** | `model, UrlParams[] ` | post object model |
|
|
107
|
+
| **put** | `model, UrlParams[]` | put object model |
|
|
108
|
+
| **head** | `model, UrlParams[]` | get head for model |
|
|
109
|
+
| **delete** | `UrlParams[]` | remove object by params |
|
|
110
|
+
| **jsonp** | `UrlParams[]` | get jsonp data |
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
# Production mode
|
|
115
|
+
===
|
|
116
|
+
Nice things to do in production mode:
|
|
117
|
+
|
|
118
|
+
**1. Disable warnings.**
|
|
119
|
+
|
|
120
|
+
If you don't wanna see warning, disable it like this:
|
|
121
|
+
```ts
|
|
122
|
+
if (environment.production) {
|
|
123
|
+
Resource.enableWarnings = false;
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
# Angular 2+ ngZone
|
|
128
|
+
If you are using Angular 2+ you need to do this in your root **app.component**:
|
|
129
|
+
```ts
|
|
130
|
+
constructor(zone:NgZone) {
|
|
131
|
+
Resource.initAngularNgZone(zone)
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
|
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.
|