Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
contensis-delivery-api
Advanced tools
Client for retrieving content using the read-only Contensis Delivery API
Create a Contensis client that allows you to query and retrieve entries, site view nodes, content types and projects. It can be used in all your JavaScript / TypeScript projects, whether it runs in a browser, Node.js app, or both.
Explore the docs on contensis.com and the contensis-delivery-api-examples repository containing Express.js, React and Angular test applications, as well as an extended example using nodes api in a Node.js project.
Use with Contensis version 12.0 and above. For Contensis 11.3 support use this version | npm. This library requires Node.js 14 or above.
Install the package to your project dependencies
using npm, or your preferred Node.js package manager.
npm install --save contensis-delivery-api
Follow the examples with the preferred coding style that best suits your project
All of the delivery methods are available under the client
instance returned by Client.create(...)
Use the provided intellisense to guide you where it is available
// Using TypeScript, or ES Module syntax
import { Client } from "contensis-delivery-api";
const client = Client.create({
rootUrl: "https://my-cms.com",
accessToken: "DELIVERY_API_ACCESS_TOKEN",
projectId: "website",
language: "en-GB",
versionStatus: "published",
});
// Using Common JS syntax
const Client = require("contensis-delivery-api").Client;
const client = Client.create({
rootUrl: "https://my-cms.com",
accessToken: "DELIVERY_API_ACCESS_TOKEN",
projectId: "website",
language: "en-GB",
versionStatus: "published",
});
Reusing the client
instance we created above
// Using TypeScript, or ES Module syntax
const loadMovies = async () => {
const movieList = await client.entries.list({
contentTypeId: "movie",
pageOptions: { pageIndex: 0, pageSize: 10 },
order: ["-releaseDate"],
});
for (const movie of movieList.items) {
console.log(movie);
}
};
loadMovies();
Keep a common client configuration and create the delivery client when you need it
// Using async / await syntax (avoiding callbacks)
// Import the additional "Config" type when using TypeScript
import { Client, Config } from "contensis-delivery-api";
// Remove ": Config" annotation when NOT using TypeScript
const contensisConfig: Config = {
rootUrl: "https://my-cms.com",
accessToken: "DELIVERY_API_ACCESS_TOKEN",
projectId: "website",
language: "en-GB",
versionStatus: "published",
};
const loadMovies = async () => {
const client = Client.create(contensisConfig);
const movieList = await client.entries.list({
contentTypeId: "movie",
pageOptions: { pageIndex: 0, pageSize: 10 },
order: ["-releaseDate"],
});
for (const movie of movieList.items) {
console.log(movie);
}
};
loadMovies();
// Using Promises and callbacks
import { Client } from "contensis-delivery-api";
const contensisConfig = {
rootUrl: "https://my-cms.com",
accessToken: "DELIVERY_API_ACCESS_TOKEN",
projectId: "website",
language: "en-GB",
versionStatus: "published",
};
function loadMovies() {
const client = Client.create(contensisConfig);
client.entries
.list({
contentTypeId: "movie",
pageOptions: { pageIndex: 0, pageSize: 10 },
order: ["-releaseDate"],
})
.then((movieList) => {
console.log(movieList.items);
});
}
loadMovies();
For more examples refer to our documentation on contensis.com
This library uses the fetch
API and relies on it being available at runtime.
In modern browsers fetch
is available natively, a polyfill is provided for older browsers.
The build of the library that targets browsers can be found in the bundle
folder.
When using this library in Node.js the fetch
API is already polyfilled with cross-fetch
package (which uses node-fetch
when used with a Node.js runtime).
Node.js version 16 introduced experimental support for a native global fetch
API and shipped as standard with Node.js versions 18 and 20. The global fetch
support in Node.js version 21 and greater is marked as stable.
You can override the built-in fetch API by providing your own fetchFn
method when creating the Client.
Method calls that require fetch invoked from this client instance will be made using your chosen API.
import { Client } from "contensis-delivery-api";
import enterpriseFetch from "enterprise-fetch";
const client = Client.create({
rootUrl: "https://my-cms.com",
accessToken: "DELIVERY_API_ACCESS_TOKEN",
projectId: "website",
language: "en-GB",
versionStatus: "published",
fetchFn: enterpriseFetch,
});
[1.5.0] - 2024-10-10
FAQs
Client for retrieving content using the read-only Contensis Delivery API
The npm package contensis-delivery-api receives a total of 899 weekly downloads. As such, contensis-delivery-api popularity was classified as not popular.
We found that contensis-delivery-api demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.