Consume a Component Resource

These are our Consume commands.

SDKs to consume Components and other entities.

Consume a Component Resource

Consume a component resource in your project.

const Component = require('linkapi-sdk/core/component');

const defaultOptions = {
   headers: {},
   queryString: {}
};

const myComponent = new Component('myComponent', defaultOptions);
const resourceMethod = 'GET'; // 'POST' | 'PUT' | 'DELETE' | 'PATCH'
const resourceName = 'products/{id}';

const result = await myComponent.request(resourceMethod, resourceName, {
   body: {},
   headers: {},
   queryString: {},
   params: {
      id: '1'
   }
})
Command (parameters)Description
componentNameRepresents the internalName registered on the Component.
httpMethodWhich HTTP method that would be used.
resourceNameThe Resource URL to be called.
paramsUse when there is dynamic parameters on the Resouce URL. For example:
resource: 'users/{id}'
resource: 'example/{id}'
urlParams: { id: '123' }
queryStringSend additional info via QueryString
credentialsAt the moment of creation of your Component, you set the Authentication Type. Once inside LinkApi, the consume follows some rules:
- If you send the credentials in the Consume, they will be used,
- If not, we will search for a registered credential inside the Tenant,
- If none of the criterias meet, the test credential will be used.

Consume Private Component

Use a Private Component in your project.

const products = await linkapi.component.request('componentName', {
        httpMethod: 'GET',
        resource: 'products',
        urlParams: {},
        queryString: {},
        credentials: {},
});

Consume Function

Consume a Function to your project from Packages.

const result = await linkapi.function.execute('my-function', 'param1');
nameRepresents the file name of your Function.
originAccepts project or package.