Skip to Content

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

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.

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Sep 02 at 04:58 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.