Create fetching data all format by use Unirest on Nodejs

My problem
- Receiver want data multi-format. (JSON, FORM and other)
- I want to write 1 function for use it.
- I want to use Promise function 1 process.
- I want to fetching data on one line.

Can use it on : 
NPM

GITHUB

https://github.com/thinnakrit/multi-fetch

Go to try !!

  1. Write function for fetching data (ES6 coding) and save name ‘fetch.js’
const unirest = require('unirest');
const FETCHING_DATA = (url, data, method, format) => {
  const formatList = {
     'json': 'application/json',
     'form': 'multipart/form-data'
}
  const headers = {'Accept': '*' ,'Content-Type': formatList[format]}
const response = new Promise(reslove => {
      if (format === 'post'){
           if (format === 'json')
unirest.post(url)
.headers(
headers)
.send(data)
.end(function (response) {
resolve(response);
});
           else if (format === 'form')
               unirest.post(url)
.headers(
headers)
.form(data)
.end(function (response) {
resolve(response);
});
      } else if (format === 'get') {
if (format === 'json')
unirest.get(url)
.headers(
headers)
.send(data)
.end(function (response) {
resolve(response);
});
            else if (format === 'form')
               unirest.get(url)
.headers(
headers)
.form(data)
.end(function (response) {
resolve(response);
});
      }
  })
  return response;
}
module.exports = {
   FETCHING_DATA
}

2. Use function for fetching data and save file name ‘test.js’

const FETCHING_DATA = require('./fetch').FETCHING_DATA
   const Test = (props) => {
const data = {
foo: '1234',
bar: '5678'
}
   const response = FETCHING_DATA('https://api.domain.com', data, 'post', 'json')
   console.log('TEST RESPONSE', response);
}

Success on two steps !!