Skip to content

Allow to call axios with method and url passed in args.meta #152

@mastersilv3r

Description

@mastersilv3r

The Problem

Currently axios takes only fnNameInWorkflow

The Solution

Allow to pass method and url as well.

How will we solve

Add this code in execute()

let {
      meta: { fnNameInWorkflow, method, url },
      data,
      headers,
      ...rest //the remaining arguments of the axios call
    } = args;

    if (fnNameInWorkflow) {
      let urlParts;
      [, , method, ...urlParts] = fnNameInWorkflow.split('.');
      url = urlParts.join('.');
    }
    if (!method || !url) {
      return new GSStatus(false, 400, 'method or url not found in axios call', fnNameInWorkflow || {method, url});
    }

Test Cases

In a typescript file, call an axios datasource like this, and end result should be same as calling a yaml flow (pasted below this ts code)

TS Code

import { GSContext, GSDataSource, logger, PlainObject } from "@godspeedsystems/core";

export default async function (ctx: GSContext, args: {loan_offer: PlainObject, pan_number: string}) {
    const client: GSDataSource = ctx.datasources.lms;
    //No need to write boilerplate for retry and token refresh here
    const res =  await client.execute(ctx, {
        meta: {
            method: 'post',
            url: '/anything',
        },
        data: args
    });
    return res;
};

YAML code

summary: Create user loan account in the LMS 
id: create_loan_account
tasks:
  - id: create_account_lms
    description: Fetching loan offers
    fn: datasource.lms.post./anything
    args: 
      data: <%inputs%>

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions