epam-cross-platform-lab / swagger-dart-code-generator

Swagger/OpenAPI code generator based on Chopper and JsonAnnotation for Flutter
Apache License 2.0
261 stars 119 forks source link

Create multiple clients for multiple endpoints #757

Closed SergeBerwert closed 2 months ago

SergeBerwert commented 3 months ago

I developed an app that connects to multiple services. how do I set up the creation for numerous clients? I can't figure out how to split the configuration in various builds in the same project.

Vovanella95 commented 2 months ago

Hi @SergeBerwert !

According current implementation, you can do the next:

You can just create several clients with different parameters (baseUrl, interceptors etc.) and use multiple clients.

final client1 = MyService.create(....); final client2 = MyService.create(....); etc...

But better way to use just one client. You can set baseUrl as a --dart-define parameter and use different baseUrl for different builds with the fully same code base.

Please, reopen the issue if I did not answered fully to your question :) Will be happy to help!