Fetching data from multiple servers with Angular frondend












1















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










share|improve this question























  • 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 '18 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 '18 at 17:53








  • 1





    Add http:// in front of your fiven url

    – Yashwardhan Pauranik
    Nov 22 '18 at 2:42
















1















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










share|improve this question























  • 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 '18 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 '18 at 17:53








  • 1





    Add http:// in front of your fiven url

    – Yashwardhan Pauranik
    Nov 22 '18 at 2:42














1












1








1








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










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 17:35









G. MuqtadaG. Muqtada

7218




7218













  • 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 '18 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 '18 at 17:53








  • 1





    Add http:// in front of your fiven url

    – Yashwardhan Pauranik
    Nov 22 '18 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 '18 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 '18 at 17:53








  • 1





    Add http:// in front of your fiven url

    – Yashwardhan Pauranik
    Nov 22 '18 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 '18 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 '18 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 '18 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 '18 at 17:53






1




1





Add http:// in front of your fiven url

– Yashwardhan Pauranik
Nov 22 '18 at 2:42





Add http:// in front of your fiven url

– Yashwardhan Pauranik
Nov 22 '18 at 2:42












2 Answers
2






active

oldest

votes


















1














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.






share|improve this answer
























  • 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 '18 at 17:48



















2














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.






share|improve this answer
























  • 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 '18 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 '18 at 19:20











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














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.






share|improve this answer
























  • 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 '18 at 17:48
















1














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.






share|improve this answer
























  • 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 '18 at 17:48














1












1








1







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 17:44









user3247458user3247458

365




365













  • 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 '18 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 '18 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 '18 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 '18 at 17:48













2














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.






share|improve this answer
























  • 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 '18 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 '18 at 19:20
















2














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.






share|improve this answer
























  • 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 '18 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 '18 at 19:20














2












2








2







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 17:50









Nikolai KieferNikolai Kiefer

196210




196210













  • 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 19:20


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents