cancel
Showing results for 
Search instead for 
Did you mean: 

consuming a service of one Node.js application in other Node.js application

0 Kudos

Dear all,

In CAP model i have two node.js applications A and B.

requirement: i have to consume application url of A in B.

is it possible to achieve this with out hardcoding the application url of A in B and without setting up a destination in cockpit.

mta.yaml

ID: test
_schema-version: '2.1'
version: 0.0.1
  - name: A
    type: nodejs
    path: srv
    parameters:
      memory: 512M
      disk-quota: 512M
    provides:
      - name: srv_api
        properties:
          url: '${default-url}'
  
  - name: B
    type: nodejs
    path: njs_test
    parameters:
      memory: 512M
      disk-quota: 1024M
    provides:
      - name: njs_test_api
        properties:
          url: '${default-url}'

Thank you.

Pratheek.

Accepted Solutions (1)

Accepted Solutions (1)

klaus_kopecz
Participant

That's what MTAs are made for 🙂 Try this: (see also my comments in mta.yaml)

ID: test
_schema-version: '3'  # you should use API version 3
version: 0.0.1
modules:              # this modules-section is missing in your example
  - name: A
    type: nodejs
    path: srv
    parameters:
      memory: 512M
      disk-quota: 512M
    provides:
      - name: srv_api
        properties:
          url: '${default-url}'  # you don't need to use ' '
  
  - name: B
    type: nodejs
    path: njs_test
    parameters:
      memory: 512M
      disk-quota: 1024M
    provides:                # for whom are you providing this?
      - name: njs_test_api
        properties:
          url: '${default-url}'

    requires:
     - name: srv_api        # provided by A
       properties:
         fromA_url: ~{url}
     
<br>

With this, the URL from A gets injected into the environment variable 'fromA_url' of B during deployment of the MTA. In a customer handler in B, you have to read in this environment variable. Alternatively, you can use the CDS API support for handling environments (see https://cap.cloud.sap/docs/advanced/config#application-configuration)

-Klaus

Answers (0)