This wraps the REST API implementation of Cascade Server CMS into a Node.js module. While some operations have easy to use functions, currently not all do. In addition to the wrapper functions, there is also a generic API Call, which you can use to complete any operation, an example is provided later on.
This is installed as a node module in your project. In your node project, run the following command:
npm install cascade-api-node
You can also clone or download the files, and install them locally.
npm install ./local-folder-path
Once it's installed, require it in your node project and create a new Cascade object. Then you can call functions on that object.
const Cascade = require("cascade-api-node");
const cascadeAPI = new Cascade("https://cascade.example.edu",{apiKey:"API-KEY-HERE"},"siteName");
The second parameter is an authentication object, while use of an API Key is recommended, it can also accept a username and password.
const cascadeAPI = new Cascade("https://cascade.example.edu",{username:"username",password:"password"},"siteName");
The site name parameter in the constructor is optional. If left off, all api calls will be done using ids instead.
const cascadeAPI = new Cascade("https://cascade.example.edu",{username:"username",password:"password"},"siteName");
cascadeAPI.readPage("/test/test")
.then(response=>{ console.log("Success reading page:"); })
.catch(error=>{ console.log("Error reading page:"); });
const cascadeAPI = new Cascade("https://cascade.example.edu",{username:"username",password:"password"});
cascadeAPI.readPage("96dc63ca0a0a008468d68542746cfd37")
.then(response=>{ console.log("Success reading page:"); })
.catch(error=>{ console.log("Error reading page:"); });
You can switch between the modes by calling the usePath()
or useId()
helper functions.
const cascadeAPI = new Cascade("https://cascade.example.edu",{username:"username",password:"password"});
cascadeAPI.readPage("96dc63ca0a0a008468d68542746cfd37")
.then(response=>{ console.log("Success reading page:"); })
.catch(error=>{ console.log("Error reading page:"); });
cascadeAPI.usePath("siteName");
cascadeAPI.readPage("/test/test")
.then(response=>{ console.log("Success reading page:"); })
.catch(error=>{ console.log("Error reading page:"); });
JSON object will be returned, with a success flag. Depending on the operation an asset or response might also returned. If an asset is returned, it is contained in a property named after the type. For example, a read operation for a file might look like:
{
asset: {
file: {
...
name: 'main.css',
id: '785d1da90a0a008468d68542058754f1'
}
},
success: true
}
An error will be thrown, which should be caught client side. An object will be returned with the error message included:
{
success: false,
message: 'Unable to identify an entity based on provided ' +
"entity path 'template/t1/css/test.css' and type " +
"'file'"
}
Examples will use the variable cascadeAPI
from above. These examples use paths, but ids can be used instead, as shown in the usage section.
Full documentation for every function available in the JSDocs.