Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including nypl-data-api-client with all npm packages installed. Try it out:

var nyplDataApiClient = require("nypl-data-api-client")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

nypl-data-api-client v0.0.1

Simple client for interacting with NYPL's internal data api

NYPL Data API Client

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


Install it via npm for use inside your project:

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


const NyplClient = require('nypl-data-api-client')
var client = new NyplClient({ base_url: '' })

Client options include:

  • base_url: Base URL for the api (e.g. ''). (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')


  • 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))
}) (path, data)

Returns a Promise that resolves after submitting data to path


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

For example, to post a new "TestSchema" schema:'schemas/TestSchema', '{ "name": "TestSchema", "type": "record", "fields": [ ... ] }')
  .then((resp) => {
    if (JSON.parse(resp) !== 'TestSchema') throw Error('Error creating schema...')


npm test
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free