Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert JS ES6 code to use async/await functions #302

Closed
SeannyPhoenix opened this issue Jul 9, 2020 · 1 comment
Closed

Convert JS ES6 code to use async/await functions #302

SeannyPhoenix opened this issue Jul 9, 2020 · 1 comment
Assignees
Labels
codegen config This issue could possibly be solved by adding a config option feature Feature request

Comments

@SeannyPhoenix
Copy link

SeannyPhoenix commented Jul 9, 2020

Is your feature request related to a problem? Please describe.
No problem, just updating code.

Describe the solution you'd like
I would like to convert functions to use async/await functions.

Example existing code output for nodejs-axios:

const axios = require('axios');
let data = JSON.stringify({"field":"value"});

let config = {
  method: 'post',
  url: 'https://example.com/api/v1/endpoint',
  headers: { 
    'Authorization': 'Bearer auth_token', 
    'Content-Type': 'application/json'
  },
  data : data
};

axios(config)
.then((response) => {
  console.log(JSON.stringify(response.data));
})
.catch((error) => {
  console.log(error);
});

Proposed output:

const axios = require('axios');
let data = JSON.stringify({"field":"value"});

const config = {
  method: 'post',
  url: 'https://example.com/api/v1/endpoint',
   headers: {
   'Authorization': 'Bearer auth_token',
   'Content-Type': 'application/json'
  },
  data: data
};

async function makeCall(config){
  try {
    const response = await axios(config);
    console.log(JSON.stringify(response.data));
  } catch (error) {
    console.log(error);
  }
}

makeCall(config);
@umeshp7 umeshp7 added config This issue could possibly be solved by adding a config option feature Feature request labels Sep 22, 2020
@dhwaneetbhatt dhwaneetbhatt self-assigned this Feb 23, 2023
@dhwaneetbhatt
Copy link
Contributor

This is fixed in the latest version v10.12. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codegen config This issue could possibly be solved by adding a config option feature Feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants