npm

npm’s 2019 JavaScript ecosystem survey analysis is now available!Get your copy here »

This package has been deprecated

Author message:

Please use https://www.npmjs.com/package/@nypl/nypl-data-api-client

nypl-data-api-client

0.0.1 • Public • Published

NYPL Data API Client

Helper lib for interacting with the (internal) NYPL Data API

Installation

Install it via npm for use inside your project:

npm i nypl-data-api-client --save

Usage

const NyplClient = require('nypl-data-api-client')
var client = new NyplClient({ base_url: 'http://example.com/api/v0.1/' })

Client options include:

  • base_url: Base URL for the api (e.g. 'http://example.com/api/v0.1/'). (Alternatively use NYPL_API_BASE_URL)
  • oauth_key: OAUTH key (Alternatively use NYPL_OAUTH_KEY)
  • oauth_secret: OAUTH secret (Alternatively use NYPL_OAUTH_SECRET)
  • oauth_url: OAUTH URL. (Alternatively use NYPL_OAUTH_URL)
  • log_level: Set log level (i.e. info, error, warn, debug). Default env.LOG_LEVEL or 'error'

Note that you must specify URL base for the api via base_url config (as above) or via NYPL_API_BASE_URL env variable. The value should include everything from the protocol to the version number in the path (as above). .

client.get (path, opts)

Returns a Promise that resolves content at path (e.g. 'current-schemas/Item')

Params:

  • path: String path to retrieve
  • opts: Optional options hash that may include:
    • cache: Boolean, default true. Controls whether or not response is cached (using default configuration of node-cache

For example, to get the "Item" stream schema:

client.get('current-schemas/Item').then((schema) => {
  // Now we can build an avro encoder by parsing the escaped "schema" prop:
  var avroType = require('avsc').parse(JSON.parse(schema.schema))
})

client.post (path, data)

Returns a Promise that resolves after submitting data to path

Params:

  • path: String path to retrieve
  • data: Object/data you want to POST to the endpoint

For example, to post a new "TestSchema" schema:

client.post('schemas/TestSchema', '{ "name": "TestSchema", "type": "record", "fields": [ ... ] }')
  .then((resp) => {
    if (JSON.parse(resp).data.stream !== 'TestSchema') throw Error('Error creating schema...')
  })

Testing

npm test

Keywords

none

install

npm i nypl-data-api-client

Downloadsweekly downloads

0

version

0.0.1

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability