plattar-api allows interfacing with the Plattar API.
Quick Use
https:
https:
https:
https:
Installation
npm install @plattar/plattar-api
Building For Browsers
cd plattar-api
npm install
npm run build
How to Use
- Fetch a project from the Plattar API.
const {
Project
} = require('@plattar/plattar-api');
const project = new Project('your-project-id');
project.get().then((proj) => {
}).catch((error) => {
console.error(error);
});
- Plattar API supports relationship chaining using a single request. Fetch a project from the Plattar API that includes scenes and pages. The Relationships component has a number of useful queries that can be performed.
const {
Project,
Scene,
Page
} = require('@plattar/plattar-api');
const project = new Project('your-project-id');
project.include(Scene, Page);
project.get().then((proj) => {
const scenes = proj.relationships.filter(Scene);
const pages = proj.relationships.filter(Page);
const myScene = proj.relationships.find(Scene, 'your-scene-id');
const myPage = proj.relationships.find(Page, 'your-page-id');
}).catch((error) => {
console.error(error);
});
- Plattar API also supports multiple relationship chaining using a single request. In this example we fetch a Project with Scenes and Pages aswell as SceneImage that belongs to a Scene.
const {
Project,
Scene,
Page,
SceneImage
} = require('@plattar/plattar-api');
const project = new Project('your-project-id');
project.include(Page, Scene.include(SceneImage));
project.get().then((proj) => {
const scenes = proj.relationships.filter(Scene);
scenes.forEach((scene) => {
const sceneImages = scene.relationships.filter(SceneImage);
});
}).catch((error) => {
console.error(error);
});
- Sometimes, we don't want to include everything as part of a single request. We can chain requests based on logic.
const {
Project,
Scene,
SceneImage
} = require('@plattar/plattar-api');
const project = new Project('your-project-id');
project.include(Scene);
project.get().then((proj) => {
const scenes = proj.relationships.filter(Scene);
scenes.forEach((scene) => {
const sceneImage = scene.relationships.find(SceneImage);
sceneImage.get().then((sceneImage) => {
}).catch((error) => {
console.error(error);
});
});
}).catch((error) => {
console.error(error);
});