简体   繁体   English

Nodejs + API剩余结构

[英]Nodejs + API Rest Structure

I have a legacy system that provides an api with some queries in rest/json (Delphi) in which I will need to consume this data already available. 我有一个遗留系统,该系统在REST / JSON(Delphi)中为api提供一些查询,在其中我将需要消耗此可用数据。 Then build an app using angular + nodejs, and I would like my application (client) to communicate only with my web-server on nodejs, and the web-server nodejs communicate with api, I will try to explain. 然后使用angular + nodejs构建一个应用程序,我希望我的应用程序(客户端)仅与我在nodejs上的Web服务器通信,而web-server nodejs与api通信,我将尝试解释。

MyApp -> web-server NodeJS -> api rest legacy client -> (web-server NodeJS port 80) -> (api rest/json server port 21000) MyApp-> Web服务器NodeJS-> api rest传统客户端->(web服务器NodeJS端口80)->(api rest / json服务器端口21000)

Any suggestions on how to put this structure together ?? 关于如何将这种结构放在一起的任何建议? Any help will be eternally grateful. 任何帮助将永远感激不已。 Thank you 谢谢

I think that you can definitely do this task without too much trouble, I just hope that I can give you the information that you are looking for. 我认为您可以轻松完成此任务,我只是希望我能为您提供所需的信息。 (Please ask so I can update my answer for any more details). (请询问,以便我更新我的答案以获取更多详细信息)。

Within NodeJS, you can setup an API pretty easily by using the ExpressJS framework. 在NodeJS中,您可以使用ExpressJS框架轻松地设置API。 There are a number of tutorials, as well as documentation online to get started with that. 有很多教程和在线文档可以帮助您开始。 You can create an API endpoint in your node app for each endpoint that your Delphi application has, or just create an API for the endpoints that you will need for your angular app, depends on how in depth you need it to be. 您可以在节点应用程序中为Delphi应用程序具有的每个端点创建一个API端点,或者仅为角度应用程序所需的端点创建一个API,具体取决于您需要的深度。

Within each endpoint in your node app, you will essentially want to forward the request to the Delphi app. 本质上,您将在节点应用程序的每个端点内将请求转发到Delphi应用程序。 I suggest looking into the Axios library, which is a promise based request library that you can use. 我建议研究Axios库,该库是您可以使用的基于Promise的请求库。 You can extract the parameters that were provided from AngularJS, and simply add those same parameters to your request to the Delphi app. 您可以提取AngularJS提供的参数,然后将这些相同的参数添加到对Delphi应用程序的请求中。

Finally, based on the response from axios, you will want to return that data to your AngularJS. 最后,根据axios的响应,您将需要将该数据返回到AngularJS。

I can provide links to examples or code snippets if need be, but I am assuming you already have familiarity with AngularJS and NodeJS, and you just wanted to see a potential system flow. 我可以根据需要提供示例或代码段的链接,但我假设您已经熟悉AngularJS和NodeJS,并且只想看看潜在的系统流程。 Hopefully this helps. 希望这会有所帮助。

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

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