Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

lcaresia
Copy link
Collaborator

No description provided.

@lcaresia lcaresia added the enhancement New feature or request label Feb 22, 2023
@lcaresia lcaresia self-assigned this Feb 22, 2023
@vercel
Copy link

vercel bot commented Feb 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
pipedream-docs ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 13, 2023 at 8:46PM (UTC)
pipedream-docs-redirect-do-not-edit ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Mar 13, 2023 at 8:46PM (UTC)

@vunguyenhung
Copy link
Collaborator

Hello @lcaresia @andrewjschuang, would you mind advice how can I test this? Or is this needed testing?

@andrewjschuang
Copy link
Collaborator

@vunguyenhung I think you can create two instances of each axios, e.g.

import axios from "axios";
import { axios as pipedreamAxios } from "./platform/dist/index.js";

or something like that.

And then create a config to pass in to the constructor with most or all axios parameters, make the request and see if they were really used by pipedreamAxios.

@vunguyenhung
Copy link
Collaborator

Hello @andrewjschuang, I couldn't test the action due to an error on the publish action step.

Could you check the test report below and advice how can I test it?
Axios_5544_1037.pdf

@andrewjschuang
Copy link
Collaborator

Hi @lcaresia, looking at the code, seems like the change doesn't reflect in anything in practice, since we don't remove any key from the config object.

Also, looking at the thread that originated this issue, I think it's if best we implemente the axios.create() method.

I also thought of adding a flag fullResponse with default: false in AxiosRequestConfig that enables the user to receive the whole response schema from the request instead of just data, what do you think?

@lcaresia
Copy link
Collaborator Author

lcaresia commented Mar 7, 2023

@vunguyenhung @andrewjschuang

You can test creating an test.js file on project root folder with this code:

const {
  axios, createAxiosInstance,
} = require("./platform/dist");

async function test1() {
  const createdAxios = createAxiosInstance({
    baseURL: "https://random-data-api.com/api/v2",
  });

  const response = await createdAxios.get("users");

  console.log("createdAxios:", response);
}

async function test2() {
  const data = await axios(this, {
    url: "https://random-data-api.com/api/v2/users",
    returnRawResponse: false,
  });

  console.log("onlyData:", data);
}

async function test3() {
  // const axios = createAxiosInstance({});

  const response = await axios(this, {
    url: "https://random-data-api.com/api/v2/users",
    returnRawResponse: true,
  });

  console.log("returnRawResponse:", response);
}

test1();
test2();
test3();

Copy link
Collaborator

@andrewjschuang andrewjschuang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lcaresia!
I've left some comments about some important improvements, but overall this is in the right track!

Btw, here is an example of what I mentioned in a comment below

function axios(config) {
  axios.create = (config) => console.log("Created axios instance with config:", config);
  console.log("Called axios with config:", config);
}

> axios({ method:"post" })
Called axios with config: { method: 'post' }

> axios.create({ baseUrl: "https://api.axios.com" })
Created axios instance with config: { baseUrl: 'https://api.axios.com' }

Co-authored-by: Andrew Chuang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] @pipedream/platform axios should support the ability to create custom axios constructor, or pass all standard axios options
3 participants