Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A better way to manage dynamic API url for Angular HTTP Client #1460

Closed
spawnrider opened this issue Jun 17, 2024 · 3 comments · Fixed by #1558
Closed

A better way to manage dynamic API url for Angular HTTP Client #1460

spawnrider opened this issue Jun 17, 2024 · 3 comments · Fixed by #1558
Assignees
Labels
documentation Improvements or additions to documentation workaround A workaround has been provided

Comments

@spawnrider
Copy link

What are the steps to reproduce this issue?

I need to override the baseURL api at runtime depending on the environment configuration.
For exemple :
GET '<baseURI>/api/myendpoint'

What happens?

At the moment, the only way to do this is to use a custom HTTP interceptor (https://orval.dev/guides/set-base-url#angular-http-client). This is not a practical solution, as this interceptor will be triggered for ALL my app requests (Orval-generated API or not)

What were you expecting to happen?

A convenient way to override the API URL at the runtime based on another (configuration) service without using a global HTTP interceptor.
There is multiple possibilites :

  1. Override the baseURI using the constructor or a specific setter (i.e. setBaseURI)
  2. Use a custom function / class to override the baseURI

May you have another / better idea on the subject ?

What versions are you using?

Operating System: Windows 11
Package Version: 6.26
Browser Version: N/A

@melloware melloware added the enhancement New feature or request label Jun 17, 2024
@soartec-lab
Copy link
Member

@spawnrider
you can use custom client instead of interceptor. if you need detail, please see the sample app bellow.

https://github.com/orval-labs/orval/blob/master/samples/angular-app/src/api/endpoints/pets/pets.service.ts#L46-L49

@melloware melloware added workaround A workaround has been provided and removed enhancement New feature or request labels Aug 1, 2024
@soartec-lab soartec-lab self-assigned this Aug 1, 2024
@soartec-lab
Copy link
Member

I'll update guide later.

@melloware melloware added the documentation Improvements or additions to documentation label Aug 1, 2024
@soartec-lab
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation workaround A workaround has been provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants