简体   繁体   中英

Nodejs Facade pattern for interact with different API web services

I am working with a NodeJs App and I have to call to a online web service in the logic part.

The problem is that if that web service is taken down, the whole system stop working.

To deal with this I have though in use a Facade pattern, adding another web service with the same functionality, and one offline file with similar information (but not as good as the web service's).

The idea is call the Facade (javaScript file?) from the logic part. It has to choose first the primary web service and call it, if it is down, go for the second one, and if it is also down, call the offline data file.

Any idea about how to stucture this on NodeJS?

This is a possible solution

 // Simple GET request example: $http({ method: 'GET', url: '/someUrl1' }).then(function (response) { // this callback will be called asynchronously // when the response is available }, function (response) { // called asynchronously if an error occurs // or server returns response with an error status. // In case it fails $http({ method: 'GET', url: '/someUrl2' }).then(function (response) { // this callback will be called asynchronously // when the response is available }, function (response) { // called asynchronously if an error occurs // or server returns response with an error status. // If it fails again, use JSON file here }); }); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM