Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mock Postman request into Axios?

enter image description here

enter image description here

I'm trying to construct my axios to be able to mimic the postman request but failed. Please help to have a look

const ax = axios.create({
  timeout: 30000,
  headers: {
    'content-type': 'application/x-www-form-urlencoded'
  }
});

// Attempt register operation
ax.post('https://url/5bc9ff9628d79b6d274165da/update.json', {
  body: JSON.stringify({
    json: JSON.stringify({ "stat": "Delivered" })
  })
})
.then(({ data }) => {
  console.log('DEBUG::success!!! data::', data);
})
.catch((err) => {
  console.log('DEBUG::err', err);
});  
like image 992
Isaac Avatar asked Dec 07 '18 10:12

Isaac


1 Answers

You can make use of the code-generation feature in Postman.

enter image description here Click on Code (below Save button) > Search for 'Axios' > NodeJS - Axios

postman code gen supports axios now

Docs for code generation in Postman: https://learning.getpostman.com/docs/postman/sending_api_requests/generate_code_snippets/

like image 129
Sivcan Singh Avatar answered Oct 02 '22 01:10

Sivcan Singh