wikitree-js
v0.4.0
Published
Javascript library for the WikiTree API
Downloads
102
Readme
wikitree-js
JavaScript library to access the WikiTree API for Node.js and Web environments.
Setup
Add wikitree-js
package to your project:
npm install wikitree-js
Import package:
import {getAncestors} from 'wikitree-js';
Usage
getPerson
Example 1
Async/await:
const response = await getPerson('Skłodowska-2');
Promise:
const responsePromise = getPerson('Skłodowska-2')
responsePromise.then(response => {
// ...
});
Live demo:
- Stackblitz (Web)
- Replit (Node.Js)
Example 2
Async/await:
const response = await getPerson(
'Skłodowska-2',
{
fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
}
);
Promise:
const responsePromise = getPerson(
'Skłodowska-2',
{
fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
}
);
responsePromise.then(response => {
// ...
});
Live demo:
- Stackblitz (Web)
- Replit (Node.Js)
getAncestors
Example 1
Async/await:
const response = await getAncestors('Skłodowska-2');
Promise:
const responsePromise = getAncestors('Skłodowska-2')
responsePromise.then(response => {
// ...
});
Live demo:
- Stackblitz (Web)
- Replit (Node.Js)
Example 2
Async/await:
const response = await getAncestors(
'Skłodowska-2',
{
fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
depth: 2,
}
);
Promise:
const responsePromise = getAncestors(
'Skłodowska-2',
{
fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
depth: 2,
}
);
responsePromise.then(response => {
// ...
});
Live demo:
- Stackblitz (Web)
- Replit (Node.Js)
getDescendants
Example 1
Async/await:
const response = await getDescendants('Skłodowska-2');
Promise:
const responsePromise = getDescendants('Skłodowska-2')
responsePromise.then(response => {
// ...
});
Live demo:
- Stackblitz (Web)
- Replit (Node.Js)
Example 2
Async/await:
const response = await getDescendants(
'Skłodowska-2',
{
fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
depth: 2,
}
);
Promise:
const responsePromise = getDescendants(
'Skłodowska-2',
{
fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth', 'Father', 'Mother'],
depth: 1,
}
);
responsePromise.then(response => {
// ...
});
Live demo:
- Stackblitz (Web)
- Replit (Node.Js)
getRelatives
Example
Async/await:
const response = await getRelatives(
['Skłodowska-2'],
{
getChildren: true,
getParents: true,
fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth'],
}
);
Promise:
const responsePromise = getRelatives(
['Skłodowska-2'],
{
getChildren: true,
getParents: true,
fields: ['Id', 'Name', 'FirstName', 'LastNameAtBirth'],
})
responsePromise.then(response => {
// ...
});
Live demo:
- Stackblitz (Web)
- Replit (Node.Js)
login (Node.Js)
This login method works only in Node.Js. To log in in a Web application use
Example
const auth = await login('[email protected]', 'P@s$w0Rd');
const response = await getRelatives(['Private-123'], {}, { auth });
Live demo: Replit
login (Web)
The Web login only works for apps hosted on https://apps.wikitree.com/. See WikiTree Apps page for details on how to host your app there.
The login flow works as follows:
- Redirect the user to the WikiTree login page giving it a URL to redirect back:
navigateToLoginPage('https://apps.wikitree.com/my-app');
- Once the user logs in, they will be redirected back to your app with an
authcode
URL parameter, e.g.
https://apps.wikitree.com/my-app?authcode=abc123abc
- The app needs to take this authcode and call
clientLogin
with it.
clientLogin(authcode);
- All subsequent requests to WikiTree will be authenticated.
Use getLoggedInUserName()
to get the currently logged in user's profile name.