source: src/mapservice-webclient/src-gen/gnuboat-mapservice/README.md@ 1cd45dd

debian/bullseye
Last change on this file since 1cd45dd was 5e4cb73, checked in by Joachim Langenbach <joachim.langenbach@…>, 8 years ago

Refactored mapservice

  • mapservice is a connexion python webservice with openapi defined api
  • mapservice-webclient is a angular app, consuming the openapi webservice mapservice
  • Property mode set to 100644
File size: 3.7 KB
Line 
1## @
2
3### Building
4
5To install the required dependencies and to build the typescript sources run:
6```
7npm install
8npm run build
9```
10
11### publishing
12
13First build the package then run ```npm publish```
14
15### consuming
16
17Navigate to the folder of your consuming project and run one of next commands.
18
19_published:_
20
21```
22npm install @ --save
23```
24
25_without publishing (not recommended):_
26
27```
28npm install PATH_TO_GENERATED_PACKAGE --save
29```
30
31_using `npm link`:_
32
33In PATH_TO_GENERATED_PACKAGE:
34```
35npm link
36```
37
38In your project:
39```
40npm link
41```
42
43__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages.
44Please refer to this issue https://github.com/angular/angular-cli/issues/8284 for a solution / workaround.
45Published packages are not effected by this issue.
46
47
48#### General usage
49
50In your Angular project:
51
52
53```
54// without configuring providers
55import { ApiModule } from '';
56import { HttpClientModule } from '@angular/common/http';
57
58
59@NgModule({
60 imports: [
61 ApiModule,
62 // make sure to import the HttpClientModule in the AppModule only,
63 // see https://github.com/angular/angular/issues/20575
64 HttpClientModule
65 ],
66 declarations: [ AppComponent ],
67 providers: [],
68 bootstrap: [ AppComponent ]
69})
70export class AppModule {}
71```
72
73```
74// configuring providers
75import { ApiModule, Configuration, ConfigurationParameters } from '';
76
77export function apiConfigFactory (): Configuration => {
78 const params: ConfigurationParameters = {
79 // set configuration parameters here.
80 }
81 return new Configuration(params);
82}
83
84@NgModule({
85 imports: [ ApiModule.forRoot(apiConfigFactory) ],
86 declarations: [ AppComponent ],
87 providers: [],
88 bootstrap: [ AppComponent ]
89})
90export class AppModule {}
91```
92
93```
94import { DefaultApi } from '';
95
96export class AppComponent {
97 constructor(private apiGateway: DefaultApi) { }
98}
99```
100
101Note: The ApiModule is restricted to being instantiated once app wide.
102This is to ensure that all services are treated as singletons.
103
104#### Using multiple OpenAPI files / APIs / ApiModules
105In order to use multiple `ApiModules` generated from different OpenAPI files,
106you can create an alias name when importing the modules
107in order to avoid naming conflicts:
108```
109import { ApiModule } from 'my-api-path';
110import { ApiModule as OtherApiModule } from 'my-other-api-path';
111import { HttpClientModule } from '@angular/common/http';
112
113
114@NgModule({
115 imports: [
116 ApiModule,
117 OtherApiModule,
118 // make sure to import the HttpClientModule in the AppModule only,
119 // see https://github.com/angular/angular/issues/20575
120 HttpClientModule
121 ]
122})
123export class AppModule {
124
125}
126```
127
128
129### Set service base path
130If different than the generated base path, during app bootstrap, you can provide the base path to your service.
131
132```
133import { BASE_PATH } from '';
134
135bootstrap(AppComponent, [
136 { provide: BASE_PATH, useValue: 'https://your-web-service.com' },
137]);
138```
139or
140
141```
142import { BASE_PATH } from '';
143
144@NgModule({
145 imports: [],
146 declarations: [ AppComponent ],
147 providers: [ provide: BASE_PATH, useValue: 'https://your-web-service.com' ],
148 bootstrap: [ AppComponent ]
149})
150export class AppModule {}
151```
152
153
154#### Using @angular/cli
155First extend your `src/environments/*.ts` files by adding the corresponding base path:
156
157```
158export const environment = {
159 production: false,
160 API_BASE_PATH: 'http://127.0.0.1:8080'
161};
162```
163
164In the src/app/app.module.ts:
165```
166import { BASE_PATH } from '';
167import { environment } from '../environments/environment';
168
169@NgModule({
170 declarations: [
171 AppComponent
172 ],
173 imports: [ ],
174 providers: [{ provide: BASE_PATH, useValue: environment.API_BASE_PATH }],
175 bootstrap: [ AppComponent ]
176})
177export class AppModule { }
178```
Note: See TracBrowser for help on using the repository browser.