compare-api-versions

1.0.0 • Public • Published

compare-api-versions

This module was created for the purpose of comparing the responses of an old and new version of an API.

How to use

1 - Create a new instance of the module

const compareModule = require('comparie-api-versions')

// create a new instance
const compare = new compareModule.CompareVersions({
  oldApi: oldApi, // The function used to call the old API
  newApi: newApi, // The function used to call the new API
  listOfIds: [ // The list of IDs to test
    000000000,
    111111111,
    222222222
  ], 
  paramsToExclude: [ // Specify any parameters to exclude from the comparision (i.e. dates)
    'date_time_updated',
    'date_time_reported'
  ],
  pathToLogs: __dirname, // Specify where to output difference logs
  timeBetweenCompareRequests: 1000 // Specify how long (in milliseconds) to wait between requests (default is 1 second) 
})

2 - After creating a new instance, call the makeComparision function

compare.makeComparison().then(() => {
  console.log('Finished running compare script')
}).catch(err => {
  console.error(err);
})

3 - Create the test calls in separate files. Include any required authorization.

const request = require('request-promise')

async function makeGetRequest (url) {
  let requestParams = {
    'url': url,
    'method': 'GET',
    'resolveWithFullResponse': true,
    'simple': false,
    'headers': {
      'Content-Type': 'application/json',
      'Accept': 'application/json'
    }
  }

  return await request(requestParams)
}

exports.getRequest = async function (id) {
  const url = `http://your_endpoint_here/${id}`
  return makeGetRequest(url)
}

4 - Putting it all together, your index.js file might look like

const compareModule = require('comparie-api-versions')
const oldApi = require('./oldApi.js').getRequest
const newApi = require('./newApi.js').getRequest

// create a new instance
const compare = new compareModule.CompareVersions({
  oldApi: oldApi, // The function used to call the old API
  newApi: newApi, // The function used to call the new API
  listOfIds: [ // The list of IDs to test
    000000000,
    111111111,
    222222222
  ],
  paramsToExclude: [ // Specify any parameters to exclude from the comparision (i.e. dates)
    'date_time_updated',
    'date_time_reported'
  ],
  pathToLogs: __dirname, // Specify where to output difference logs
  timeBetweenCompareRequests: 1000 // Specify how long (in milliseconds) to wait between requests (default is 1 second) 
})

compare.makeComparison().then(() => {
  console.log('Finished running compare script')
}).catch(err => {
  console.error(err);
})

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i compare-api-versions

      Weekly Downloads

      0

      Version

      1.0.0

      License

      Apache-2.0

      Unpacked Size

      19.7 kB

      Total Files

      5

      Last publish

      Collaborators

      • brogerm