繁体   English   中英

用于与不同API Web服务进行交互的Nodejs Facade模式

[英]Nodejs Facade pattern for interact with different API web services

我正在使用NodeJs应用程序,因此必须在逻辑部分中调用在线Web服务。

问题是,如果该Web服务被关闭,则整个系统将停止工作。

为了解决这个问题,我使用了Facade模式,添加了另一个具有相同功能的Web服务以及一个具有类似信息的脱机文件(但不如Web服务的好)。

这个想法从逻辑部分称为Facade(javaScript文件?)。 它必须首先选择主要的Web服务并调用它,如果它关闭了,则选择第二个,如果它也关闭了,则调用脱机数据文件。

关于如何在NodeJS上进行构造的任何想法?

这是一个可能的解决方案

 // 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 }); }); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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