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.
Using npm:
npm i theoneapi-client-sdk
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.
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
}
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
}
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
},
]
}