1.0.2 • Published 1 year ago

theoneapi-client-sdk v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

The One API Client SDK

A Node.js client for integrating with The One API. You must acquire an access token to use it by creating an account through The One API site.

Installation

Using npm:

npm i theoneapi-client-sdk

Getting Started

Create an account and get an access token through The One API site.

Import the module in your code:

const TheOneApiClient = require('theoneapi-client-sdk');

Create an instance of the client with your access token:

const client = new OneApiClient('YOUR_ACCESS_TOKEN');

You can now use the client to make async requests to the various endpoints of The One API.

Examples

List data from an endpoint

Request

const result = await client.listQuotes();

Response

{
  "docs": [
    {
      "_id": "5cd96e05de30eff6ebcce7e9",
      "dialog": "Deagol!",
      "movie": "5cd95395de30eff6ebccde5d",
      "character": "5cd99d4bde30eff6ebccfe9e",
      "id": "5cd96e05de30eff6ebcce7e9"
    },
    {
      "_id": "5cd96e05de30eff6ebcce7ea",
      "dialog": "Deagol!",
      "movie": "5cd95395de30eff6ebccde5d",
      "character": "5cd99d4bde30eff6ebccfe9e",
      "id": "5cd96e05de30eff6ebcce7ea"
    },
    {
      "_id": "5cd96e05de30eff6ebcce7eb",
      "dialog": "Deagol!",
      "movie": "5cd95395de30eff6ebccde5d",
      "character": "5cd99d4bde30eff6ebccfe9e",
      "id": "5cd96e05de30eff6ebcce7eb"
    },
    ...
  ],
  "total": 2390,
  "limit": 1000,
  "offset": 0,
  "page": 1,
  "pages": 3
}

Get data by ID from an endpoint

Request

const result = await client.getQuoteById('5cd96e05de30eff6ebcce7e9');

Response

{
  "docs": [
    {
      "_id": "5cd96e05de30eff6ebcce7e9",
      "dialog": "Deagol!",
      "movie": "5cd95395de30eff6ebccde5d",
      "character": "5cd99d4bde30eff6ebccfe9e",
      "id": "5cd96e05de30eff6ebcce7e9"
    }
  ],
  "total": 1,
  "limit": 1000,
  "offset": 0,
  "page": 1,
  "pages": 1
}

Sort, Pagination, and Filtering

Results can be sorted, paginated and filtered for more fine-grained control of the data returned. Each client call takes an optional queryOptions param that contains these options in the below format:

const queryOptions = {
     sortOptions: {
         sortPropertyName: 'name',
         sortDirection: SortDirections.ASC
     },
     paginationOptions: {
         limit: 10, // If not provided, the default limit is 1000
         page: 2,
         offset: 20
     },
     filterOptions: [ // Multiple filters can be provided in an array
        {
            filterPropertyName: "name", // The name of the property to filter on
            filterType: FilterTypes.MATCH, // The filter type
            filterValue: "Gandalf" // The value to filter on
        },
    ]
}

See Also

The One API Documentation

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago