Lord of the Ring Node Library provides convenient access to the The One API for applications written in server-side JavaScript.
The official documentation for The One API
can be found here
Currently the library only support the Movie endpoints:
/movies
/movies/:id
/movies/:id/quotes
Install the package with:
npm install lotr-node-sdk --save
# or
yarn add lotr-node-sdk
The library needs to be used with your access token, which is available in the The One Api Account Page. To use the SDK, you can pass the token into LOTRApi()
import LOTRApi from 'lotr-node-sdk';
const client = new LOTRApi('YOUR_ACCESS_TOKEN');
client.movie
.getMovieById('5cd95395de30eff6ebccde5d')
.then((movie) => console.log(movie))
.catch((error) => console.error(error));
Or using async
/await
:
import LOTRApi from 'lotr-node-sdk';
const client = new LOTRApi('YOUR_ACCESS_TOKEN');
const movie = await client.movie.movie('5cd95395de30eff6ebccde5d');
console.log(movie);
You can also specify pagination options by passing in an option object specifying pagination options to all endpoint methods (eg. getMovieById
) such as limit
, offset
or page
.
Note: Usage of both offset
and page
is not supported
import LOTRApi from 'lotr-node-sdk';
const client = new LOTRApi('YOUR_ACCESS_TOKEN');
const options = {
pagination: {
limit: 10,
page: 1,
},
};
const movie = await client.movie.getQuotesByMovieId(
'5cd95395de30eff6ebccde5d',
options
);
console.log(movie);
List of all movies, including the "The Lord of the Rings" and the "The Hobbit" trilogies
client.movie.getMovies();
Request one specific movie
client.movie.getMovieById('SOME_ID');
Request all movie quotes for one specific movie (only working for the LotR trilogy)
client.movie.getQuotesByMovieId('SOME_ID');
Filter and sorting are not yet supported in this library
Run all tests:
yarn install
yarn test