dingo-loader

1.0.0 • Public • Published

dingo-loader

A node.js module for deserializing resources from a dingo-based REST API, or any JSON API that carries a payload under data[<some-object-key>]. For example, let's say you request.get a feed that looks like this:

{
  "status_code" : 200,
  "message" : "OK",
  "data" : {
    "products" : {
      "1" : {
        "id" : 1,
        "name" : "some product" 
      },
      "2" : {
        "id" : 2,
        "name" : "some other product"
      }
    }
  }
}

and you want an array like this:

[
  {
    id: 1,
    name: 'some product'
  },
  {
    id: 2,
    name: 'some other product'
  }
]

What you want is:

const dingoLoader = require('dingo-loader');
 
var arrayOfValues = dingoLoader(myJsonResponse);
 

Constraints:

  • If status_code is present, it must be in the 200's range.
  • If message is present, must be "OK".
  • data must be an object with only one key.

Package Sidebar

Install

npm i dingo-loader

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • mitchellst