Ways to call an API in one Nodejs application from another Nodejs application

Our application will have a website and a mobile application that will communicate with the same API. I have one Nodejs application for serving only APIs and a second Nodejs application serving html pages for a website. I am using Expressjs for both of these applications.

What are the different methods of calling an API in one Nodejs from another Nodejs application? More information on when to use each method would be great.

EDIT:

Example, I have the following applications

  • NodejsAPI (node ​​and express)
  • NodejsWebsite (node ​​and express)
  • Mobileapp

NodejsAPI will provide API access for MobileApp and NodejsWebsite. MobileApp will access the API via http. But I want to know what options for NodejsWebsite to call the API in the NodejsAPI application. As far as I understand, this will be interprocess communication between two processes. For .net applications, this communication can be done using .net channels, tcp communication, etc. What are the equivalent methods for Nodejs applications on unix and linux platforms?

Thoughts from an IPC perspective I found the following helpful,
What is the most efficient library / method for exchanging data between various node.js technologies? https://www.npmjs.org/package/node-ipc

+3
rest api ipc
source share
1 answer

There, the node client is http: // vanilla , the http client is a Swiss army knife, the request , then the superspy, similar to jQuery.ajax . To make life easier for you armrest and fementa , both have different tastes of the same.

Now, if you want to achieve better performance and have a different interface for your application, you can use one of these RPC solutions:

  • dnode : one of the most popular solutions. This makes things very easy. It provides seamless use of remote interfaces. phantomjs-node uses dnode. Doesn't work with huge objects compared to others. For small things, this is perfect. There are other ports for other languages.

  • zerorpc : Uses zeromq as a socket library known for reliability. It also supports connecting to the python client.

  • smith : RPC systems used in the backend of cloud9. Basically almost as good as dnode, but faster. Both the cult and zerorpc use msgpack instead of JSON, so they will store bytes on the wire.

  • axon-rpc : easy option. How nice to use zerorpc. You can configure it to use msgpack with axon-msgpack .

All of the above works both with TCP (for use on different computers) and with Unix Domain Sockets (faster than TCP, but only on one computer).

If you want to improve performance, you can embed your NodejsAPI into your NodejsWeb site just by requiring its interface.

If you want better answers than this, write a more specific question. The question as it is is too broad.

+6
source share

All Articles