Importing Code from Another Point

Code points support the ability to import code from other code points. The execute_process function can call an imported point by referencing its name and passing a single parameter as an object.

Step 1: Prepare the Code for the "say_something" Point

Create a file named say_something.js with the following content:

async function execute_process({ some_text }) {
  return `Here's your text: ${some_text}`;
}

Step 2: Prepare the Code for the "import_test" Point

Create a file named import_test.js with the following content:

async function execute_process({ some_text }) {
  return {
    some_output: await say_something({ some_text: "This is the output" })
  };
}

Step 3: Upload the Code Points

Upload the say_something and import_test points. Ensure that the say_something point is included inside the imports key when uploading the import_test point.

Upload say_something.js

curl --request POST \
     --url https://<domain>.melodyarc.app/api/v1/code \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --header 'x-api-key: APIKEY' \
     --data '{
  "version": "latest",
  "language": "javascript",
  "organization_id": "org_abc123",
  "name": "say_something",
  "code": "'"$(cat say_something.js)"'",
  "tags": [
    "test"
  ]
}'

Upload import_test.js

curl --request POST \
     --url https://<domain>.melodyarc.app/api/v1/code \
     --header 'accept: application/json' \
     --header 'content-type: application/json' \
     --header 'x-api-key: APIKEY' \
     --data '{
  "version": "latest",
  "language": "javascript",
  "organization_id": "org_abc123",
  "name": "import_test",
  "code": "'"$(cat import_test.js)"'",
  "imports": ["say_something"],
  "tags": [
    "test"
  ]
}'