1 | # @mello-labs/api-tools
|
2 |
|
3 | ## Installation
|
4 |
|
5 | To install this library, run:
|
6 |
|
7 | ```bash
|
8 | $ npm install @mello-labs/api-tools --save
|
9 | ```
|
10 |
|
11 | ## Consuming your library
|
12 |
|
13 | Once you have published your library to npm, you can import your library in any Angular application by running:
|
14 |
|
15 | ```bash
|
16 | $ npm install @mello-labs/api-tools
|
17 | ```
|
18 |
|
19 | and then from your Angular `AppModule`:
|
20 |
|
21 | ```typescript
|
22 | import { BrowserModule } from '@angular/platform-browser';
|
23 | import { NgModule } from '@angular/core';
|
24 |
|
25 | import { AppComponent } from './app.component';
|
26 |
|
27 | // Import your library
|
28 | import { ApiToolsModule, ApiReducer, ApiStatusReducer } from '@mello-labs/api-tools';
|
29 |
|
30 | @NgModule({
|
31 | declarations: [
|
32 | AppComponent
|
33 | ],
|
34 | imports: [
|
35 | BrowserModule,
|
36 |
|
37 | // Specify your library as an import
|
38 | StoreModule.forRoot({ api: ApiReducer, apiStatus: ApiStatusReducer}),
|
39 | // Specify your library as an import
|
40 | ApiToolsModule.forRoot()
|
41 | ],
|
42 | providers: [],
|
43 | bootstrap: [AppComponent]
|
44 | })
|
45 | export class AppModule { }
|
46 | ```
|
47 |
|
48 | To use the API Store automation service, see below.
|
49 |
|
50 | ```typescript
|
51 | import { ApiHttpService, ApiActions } from '@mello-labs/api-tools';
|
52 |
|
53 | export class ApiService extends ApiHttpService {
|
54 |
|
55 | constructor(
|
56 | private http: HttpClient,
|
57 | private store: Store<IStore.root>,
|
58 | private router: Router
|
59 | ) {
|
60 | super(http, store, router);
|
61 | }
|
62 |
|
63 | /** Sample store usage */
|
64 | public users = {
|
65 | get: (update?: boolean) => this.getStore(ApiMap.users.endpoint, ApiMap.users, update),
|
66 | getOne: (user, update?: boolean) => this.getStore(ApiMap.users.endpoint + '/' + user.id, ApiMap.users, update),
|
67 | post: (user) => this.postStore(ApiMap.users.endpoint, ApiMap.users, user),
|
68 | put: (user) => this.putStore(ApiMap.users.endpoint + '/' + user.id, ApiMap.users, user),
|
69 | delete: (user) => this.deleteStore(ApiMap.users.endpoint + '/' + user.id, ApiMap.users, user)
|
70 | }
|
71 | }
|
72 | ```
|
73 |
|
74 | Once your library is imported, you can use its components, directives and pipes in your Angular application:
|
75 |
|
76 | ```xml
|
77 | <!-- You can now use your library component in app.component.html -->
|
78 | <h1>
|
79 | {{title}}
|
80 | </h1>
|
81 | <sampleComponent></sampleComponent>
|
82 | ```
|
83 |
|
84 | ## Development
|
85 |
|
86 | To generate all `*.js`, `*.d.ts` and `*.metadata.json` files:
|
87 |
|
88 | ```bash
|
89 | $ npm run build
|
90 | ```
|
91 |
|
92 | To lint all `*.ts` files:
|
93 |
|
94 | ```bash
|
95 | $ npm run lint
|
96 | ``` |
\ | No newline at end of file |