Fetching data from multiple servers with Angular frondend
up vote
1
down vote
favorite
We are developing an ERP with multiple back-ends running on various servers, for example,
hr at abc.com/hr/api
finance at xyz.com/api
and so on
But we have single front-end Angular 6 application, we may be fetching data from various servers at a time.
I am new to Angular, but what little bit I know is we can define variables in environment.ts for either development , production or test server, but what If I bypass enviroment.ts settings with what ever http url I want.
Thanks
angular
add a comment |
up vote
1
down vote
favorite
We are developing an ERP with multiple back-ends running on various servers, for example,
hr at abc.com/hr/api
finance at xyz.com/api
and so on
But we have single front-end Angular 6 application, we may be fetching data from various servers at a time.
I am new to Angular, but what little bit I know is we can define variables in environment.ts for either development , production or test server, but what If I bypass enviroment.ts settings with what ever http url I want.
Thanks
angular
I think you still can useenv
file by making the variables for URLs and use them according to your need inside your service while making API calls.
– Yashwardhan Pauranik
Nov 21 at 17:43
@YashwardhanPauranik When I write a service like getEmployees(): Observable<any>{ return this.http.get('localhost:3000/employees'); } I get unknow url error
– G. Muqtada
Nov 21 at 17:53
1
Add http:// in front of your fiven url
– Yashwardhan Pauranik
Nov 22 at 2:42
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
We are developing an ERP with multiple back-ends running on various servers, for example,
hr at abc.com/hr/api
finance at xyz.com/api
and so on
But we have single front-end Angular 6 application, we may be fetching data from various servers at a time.
I am new to Angular, but what little bit I know is we can define variables in environment.ts for either development , production or test server, but what If I bypass enviroment.ts settings with what ever http url I want.
Thanks
angular
We are developing an ERP with multiple back-ends running on various servers, for example,
hr at abc.com/hr/api
finance at xyz.com/api
and so on
But we have single front-end Angular 6 application, we may be fetching data from various servers at a time.
I am new to Angular, but what little bit I know is we can define variables in environment.ts for either development , production or test server, but what If I bypass enviroment.ts settings with what ever http url I want.
Thanks
angular
angular
asked Nov 21 at 17:35
G. Muqtada
7218
7218
I think you still can useenv
file by making the variables for URLs and use them according to your need inside your service while making API calls.
– Yashwardhan Pauranik
Nov 21 at 17:43
@YashwardhanPauranik When I write a service like getEmployees(): Observable<any>{ return this.http.get('localhost:3000/employees'); } I get unknow url error
– G. Muqtada
Nov 21 at 17:53
1
Add http:// in front of your fiven url
– Yashwardhan Pauranik
Nov 22 at 2:42
add a comment |
I think you still can useenv
file by making the variables for URLs and use them according to your need inside your service while making API calls.
– Yashwardhan Pauranik
Nov 21 at 17:43
@YashwardhanPauranik When I write a service like getEmployees(): Observable<any>{ return this.http.get('localhost:3000/employees'); } I get unknow url error
– G. Muqtada
Nov 21 at 17:53
1
Add http:// in front of your fiven url
– Yashwardhan Pauranik
Nov 22 at 2:42
I think you still can use
env
file by making the variables for URLs and use them according to your need inside your service while making API calls.– Yashwardhan Pauranik
Nov 21 at 17:43
I think you still can use
env
file by making the variables for URLs and use them according to your need inside your service while making API calls.– Yashwardhan Pauranik
Nov 21 at 17:43
@YashwardhanPauranik When I write a service like getEmployees(): Observable<any>{ return this.http.get('localhost:3000/employees'); } I get unknow url error
– G. Muqtada
Nov 21 at 17:53
@YashwardhanPauranik When I write a service like getEmployees(): Observable<any>{ return this.http.get('localhost:3000/employees'); } I get unknow url error
– G. Muqtada
Nov 21 at 17:53
1
1
Add http:// in front of your fiven url
– Yashwardhan Pauranik
Nov 22 at 2:42
Add http:// in front of your fiven url
– Yashwardhan Pauranik
Nov 22 at 2:42
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
I am not a pro either in Angular. Have been working on Angular from 6 months now.
So upto my knowledge, the preferred practice is to declare the Base Url in the environment.ts. When you BUILD the angular project it only takes the PROD environment.ts.
Now, coming to your question "but what If I bypass enviroment.ts settings with what ever http url I want."
What I understand is
if you don't define the base url in the environment.ts file you'll have to declare it in any of your component, that kind of works but if you someday have to change your Base url you'll have to change the link from each and every component you are using it in. So better stick with environment.ts.
I hope that answers your question rightly.
Thanks ,but can i define for example 3 variable urls in PROD environment, so that I can switch to what ever url I want.
– G. Muqtada
Nov 21 at 17:48
add a comment |
up vote
2
down vote
Angular should not be concerned where it gets its Data from. You can contact multiple APIs. You dont have to specify the api url youre targeting in the environment (it makes it easier if youre always targeting the same api).
Or you can define multiple Api urls in the environment under different names e.g. API_URL_HR="" API_URL_FINANCE="".
The Http request needs to get the url from somewhere, but this can be an environment variable or a simple String or a variable.
Great, I will be happy if can define each nested module having its own environment , and if some module doesnt have its own environment settings, app should get default environment.
– G. Muqtada
Nov 21 at 18:00
Yes, I am 90% targeting to the URL defined with environments, anyway I found the way to over write or bypass this url by adding http.disableApiPrefix().get('whatever.com');
– G. Muqtada
Nov 21 at 19:20
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
I am not a pro either in Angular. Have been working on Angular from 6 months now.
So upto my knowledge, the preferred practice is to declare the Base Url in the environment.ts. When you BUILD the angular project it only takes the PROD environment.ts.
Now, coming to your question "but what If I bypass enviroment.ts settings with what ever http url I want."
What I understand is
if you don't define the base url in the environment.ts file you'll have to declare it in any of your component, that kind of works but if you someday have to change your Base url you'll have to change the link from each and every component you are using it in. So better stick with environment.ts.
I hope that answers your question rightly.
Thanks ,but can i define for example 3 variable urls in PROD environment, so that I can switch to what ever url I want.
– G. Muqtada
Nov 21 at 17:48
add a comment |
up vote
1
down vote
accepted
I am not a pro either in Angular. Have been working on Angular from 6 months now.
So upto my knowledge, the preferred practice is to declare the Base Url in the environment.ts. When you BUILD the angular project it only takes the PROD environment.ts.
Now, coming to your question "but what If I bypass enviroment.ts settings with what ever http url I want."
What I understand is
if you don't define the base url in the environment.ts file you'll have to declare it in any of your component, that kind of works but if you someday have to change your Base url you'll have to change the link from each and every component you are using it in. So better stick with environment.ts.
I hope that answers your question rightly.
Thanks ,but can i define for example 3 variable urls in PROD environment, so that I can switch to what ever url I want.
– G. Muqtada
Nov 21 at 17:48
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
I am not a pro either in Angular. Have been working on Angular from 6 months now.
So upto my knowledge, the preferred practice is to declare the Base Url in the environment.ts. When you BUILD the angular project it only takes the PROD environment.ts.
Now, coming to your question "but what If I bypass enviroment.ts settings with what ever http url I want."
What I understand is
if you don't define the base url in the environment.ts file you'll have to declare it in any of your component, that kind of works but if you someday have to change your Base url you'll have to change the link from each and every component you are using it in. So better stick with environment.ts.
I hope that answers your question rightly.
I am not a pro either in Angular. Have been working on Angular from 6 months now.
So upto my knowledge, the preferred practice is to declare the Base Url in the environment.ts. When you BUILD the angular project it only takes the PROD environment.ts.
Now, coming to your question "but what If I bypass enviroment.ts settings with what ever http url I want."
What I understand is
if you don't define the base url in the environment.ts file you'll have to declare it in any of your component, that kind of works but if you someday have to change your Base url you'll have to change the link from each and every component you are using it in. So better stick with environment.ts.
I hope that answers your question rightly.
answered Nov 21 at 17:44
user3247458
263
263
Thanks ,but can i define for example 3 variable urls in PROD environment, so that I can switch to what ever url I want.
– G. Muqtada
Nov 21 at 17:48
add a comment |
Thanks ,but can i define for example 3 variable urls in PROD environment, so that I can switch to what ever url I want.
– G. Muqtada
Nov 21 at 17:48
Thanks ,but can i define for example 3 variable urls in PROD environment, so that I can switch to what ever url I want.
– G. Muqtada
Nov 21 at 17:48
Thanks ,but can i define for example 3 variable urls in PROD environment, so that I can switch to what ever url I want.
– G. Muqtada
Nov 21 at 17:48
add a comment |
up vote
2
down vote
Angular should not be concerned where it gets its Data from. You can contact multiple APIs. You dont have to specify the api url youre targeting in the environment (it makes it easier if youre always targeting the same api).
Or you can define multiple Api urls in the environment under different names e.g. API_URL_HR="" API_URL_FINANCE="".
The Http request needs to get the url from somewhere, but this can be an environment variable or a simple String or a variable.
Great, I will be happy if can define each nested module having its own environment , and if some module doesnt have its own environment settings, app should get default environment.
– G. Muqtada
Nov 21 at 18:00
Yes, I am 90% targeting to the URL defined with environments, anyway I found the way to over write or bypass this url by adding http.disableApiPrefix().get('whatever.com');
– G. Muqtada
Nov 21 at 19:20
add a comment |
up vote
2
down vote
Angular should not be concerned where it gets its Data from. You can contact multiple APIs. You dont have to specify the api url youre targeting in the environment (it makes it easier if youre always targeting the same api).
Or you can define multiple Api urls in the environment under different names e.g. API_URL_HR="" API_URL_FINANCE="".
The Http request needs to get the url from somewhere, but this can be an environment variable or a simple String or a variable.
Great, I will be happy if can define each nested module having its own environment , and if some module doesnt have its own environment settings, app should get default environment.
– G. Muqtada
Nov 21 at 18:00
Yes, I am 90% targeting to the URL defined with environments, anyway I found the way to over write or bypass this url by adding http.disableApiPrefix().get('whatever.com');
– G. Muqtada
Nov 21 at 19:20
add a comment |
up vote
2
down vote
up vote
2
down vote
Angular should not be concerned where it gets its Data from. You can contact multiple APIs. You dont have to specify the api url youre targeting in the environment (it makes it easier if youre always targeting the same api).
Or you can define multiple Api urls in the environment under different names e.g. API_URL_HR="" API_URL_FINANCE="".
The Http request needs to get the url from somewhere, but this can be an environment variable or a simple String or a variable.
Angular should not be concerned where it gets its Data from. You can contact multiple APIs. You dont have to specify the api url youre targeting in the environment (it makes it easier if youre always targeting the same api).
Or you can define multiple Api urls in the environment under different names e.g. API_URL_HR="" API_URL_FINANCE="".
The Http request needs to get the url from somewhere, but this can be an environment variable or a simple String or a variable.
answered Nov 21 at 17:50
Nikolai Kiefer
1618
1618
Great, I will be happy if can define each nested module having its own environment , and if some module doesnt have its own environment settings, app should get default environment.
– G. Muqtada
Nov 21 at 18:00
Yes, I am 90% targeting to the URL defined with environments, anyway I found the way to over write or bypass this url by adding http.disableApiPrefix().get('whatever.com');
– G. Muqtada
Nov 21 at 19:20
add a comment |
Great, I will be happy if can define each nested module having its own environment , and if some module doesnt have its own environment settings, app should get default environment.
– G. Muqtada
Nov 21 at 18:00
Yes, I am 90% targeting to the URL defined with environments, anyway I found the way to over write or bypass this url by adding http.disableApiPrefix().get('whatever.com');
– G. Muqtada
Nov 21 at 19:20
Great, I will be happy if can define each nested module having its own environment , and if some module doesnt have its own environment settings, app should get default environment.
– G. Muqtada
Nov 21 at 18:00
Great, I will be happy if can define each nested module having its own environment , and if some module doesnt have its own environment settings, app should get default environment.
– G. Muqtada
Nov 21 at 18:00
Yes, I am 90% targeting to the URL defined with environments, anyway I found the way to over write or bypass this url by adding http.disableApiPrefix().get('whatever.com');
– G. Muqtada
Nov 21 at 19:20
Yes, I am 90% targeting to the URL defined with environments, anyway I found the way to over write or bypass this url by adding http.disableApiPrefix().get('whatever.com');
– G. Muqtada
Nov 21 at 19:20
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53417709%2ffetching-data-from-multiple-servers-with-angular-frondend%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I think you still can use
env
file by making the variables for URLs and use them according to your need inside your service while making API calls.– Yashwardhan Pauranik
Nov 21 at 17:43
@YashwardhanPauranik When I write a service like getEmployees(): Observable<any>{ return this.http.get('localhost:3000/employees'); } I get unknow url error
– G. Muqtada
Nov 21 at 17:53
1
Add http:// in front of your fiven url
– Yashwardhan Pauranik
Nov 22 at 2:42