lab-api-wrapper

    1.0.10 • Public • Published

    Douglas Lab API wrapper

    This module provides a JavaScript wrapper for the Douglas Lab Inventory Management API.

    Building the wrapper

    $ git clone https://github.com/douglaslab/lab-api-wrapper.git
    $ cd lab-api-wrapper
    $ npm i
    $ npm run build

    Wrapper classes

    Currently (version 1.0.0) the wrapper provides 3 classes:

    1. Items - inventory management.
    2. Users - users management.
    3. Admin - log, permissions, and general operations.

    Each class accepts 2 parameters at instantiation:

    1. apiUrl - points to the root of the server serving the URL.
    2. version - the version of the API we're targeting. Defaults to latest.

    The parameters allow us to use different versions and instances of the API with different classes, although that won't be needed until several versions of the API exist.

    Sample usage

    1. Create an empty folder.
    2. Add a package.json file by running npm init in the folder and answering the questions.
    3. Add the wrapper module:
    $ npm i --save lab-api-wrapper
    $ npm i --save async  #see comment below
    1. Create a file called index.js:
    import wrapper from 'lab-api-writer';
    import async from 'async';
    const API_URL = 'https://bionano-api.herokuapp.com';
    const VERSION = '1.0.0';
    var items = new wrapper.Items(API_URL, VERSION);
    var users = new wrapper.Users(API_URL, VERSION);
     
    var myUser;
    var myItem;
     
    async.series([
      //authenticate user
      (callback) => {
        users.login('provide_user_email', 'provide_user_password', (result) => {
          myUser = result.data;
          callback();
        });
      },
      //create an item
      (callback) => {
        items.createItem(myUser, {name: 'myItem', length: '5cm'}, (result) => {
          myItem = result.data;
          callback();
        });
      },
      //delete the item
      (callback) => {
        items.deleteItem(myUser, myItem.id, (result) => {
          callback();
        });
      }
    ]);
    1. Run node index.js

    PS: the sample code makes use of the async module, to synchronize the various calls - but you can use any alternative (such as promises, Q, generators, etc.).

    Tests

    Before running tests, add a file called params.json to the tests folder:

    {
      "API_URL": "url of the API endpoint",
      "VERSION": "1.0.0",
      "ADMIN_USER": "email of an admin user",
      "ADMIN_PASSWORD": "password of an admin user"
    }

    Then run:

    $ npm test

    Keywords

    none

    Install

    npm i lab-api-wrapper

    DownloadsWeekly Downloads

    1

    Version

    1.0.10

    License

    BSD-3-Clause

    Last publish

    Collaborators

    • douglaslab