-
Notifications
You must be signed in to change notification settings - Fork 6k
-
I have generated a client from a spec that a server provided.
I chose typescript-angular client.
How do I actually use it?
Is there any documentation?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
With angular you'll typically import the api module to your module, which will give you access to the different api services within that module. Then through DI you can access them in your different components or services.
Note - make sure you're using the correct angular version, the first one is the now defunct AngularJs, Angular2 means any version of angular since v2.
I haven't used this specific library for the angular client, but the code generated from the swagger web editor would be extracted from the zip into a folder in my repo, my main app module would import ApiModule.forRoot(apiConfig)
where apiConfig would be a configuration factory that returns a Configuration object.
After this I could just include something like private fooService: FooService
in any component within that module.
With standalone it was a little different, in the ApplicationConfig options of the bootstrapApplication function you add a provider for Configuration
like so:
{ provide: Configuration, useFactory: () => new Configuration({ withCredentials: true }), },
Same thing for the BASE_PATH, then in whatever component needs access to the API client you can import the api module that the code generates and use DI to get the relevant service via the constructor again.
Beta Was this translation helpful? Give feedback.