javascriptreactjsreact-nativeaxiospostman

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);
});  

Solution

  • 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/