- Support ESImports with Easy to use imports;
- Easy manipulation of LOTR data;
- Query Information by using methods;
- SDK formatted in objects;
SDK for Lord of the rings OpenApi.
npm install;
To install dependencies.
import LOTR from 'index.ts';You can also use the default export, since the named export is just LOTR.
const LOTR = require('index.js');If you use require for importing, only default export is available:
NOTE: CommonJS usage in order to gain the TypeScript typings (for intellisense / autocomplete) while using CommonJS imports with require(), use the following approach:
import LOTR from 'index.js';
//const LOTR = require('index.js'); // legacy way
// Request books information
LOTR.books.get()
.then(function (response) {
// handle success
console.log(response);
})
.catch(function (error) {
// handle error
console.log(error);
})
.finally(function () {
// always executed
});
// Optionally the request above could also be done as
LOTR.books.get({
sort: {
property: 'age',
order: asc // order: 'asc' | 'desc'
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
// always executed
});
// Want to use async/await? Add the `async` keyword to your outer function/method.
async function getBooks() {
try {
const response = await LOTR.books.get();
console.log(response);
} catch (error) {
console.error(error);
}
}NOTE: async/await is part of ECMAScript 2017 and is not supported in Internet Explorer and older browsers, so use with caution.
async function getMovies() {
try {
const authToken ='....';
const response = await LOTR.movies.get(authToken);
console.log(response);
} catch (error) {
console.error(error);
}
}NOTE: most of the methods required auth token. You can access your Auth token by sign in.
User can customize response by passing config object.
Filtering can be performed by pass filter array into the config argument.
async function getCharacters() {
try {
const response = await LOTR.character.get({
filter: [
race: 'Human'
]
});
console.log(response);
} catch (error) {
console.error(error);
}
}Sorting can be performed by passing sort object into the config argument.
async function getCharacters() {
try {
const response = await LOTR.character.get({
sort: {
property: 'age',
order: asc // order: 'asc' | 'desc'
}
});
console.log(response);
} catch (error) {
console.error(error);
}
}Pagination can be performed by passing pagination object into the config argument.
async function getCharacters() {
try {
const response = await LOTR.character.get({
pagination: {
limit: 100,
page: 2,
offset: 0
}
});
console.log(response);
} catch (error) {
console.error(error);
}
}