The Caasy Javascript SDK is a simple and lightweight (<10kb) wrapper for the public Caasy API. It helps you fetching all your public content such as blog posts and pages. The SDK is continuously evolving. Make sure to check this site regularly for updates and changes.
Install the SDK with npm i --save @caasy/sdk-js and import it with the import or require keyword. The SDK works in the browser as well as in NodeJS. You can use it with all frameworks and libraries such as NextJS and Gatsby.
Before you use the SDK, it needs to be initialized with the init method. All you need to provide is the site ID, which you can find in the overview of all the sites you have access to. You only need to call the init function once in your app. We recommend doing it at the top of your entire app.
To fetch all published blog posts, use the getAll function. The response is paginated, starting on page 1. You can pass the desired page as a number to the function. Keep in mind that this function only fetches the basic data of a blog post and no details such as its elements.
If you are planning to use a static site generator, you might need to have a list of all blog post IDs to define, which routes are available on your site. In this scenario, you can use the getAllIds function.
Use the getAllAuthors function, if you want to fetch all the authors, that have published a blog post on the site. The response is paginated. Pass the desired page as a number to the function.
The getAllByAuthor function allows you to fetch all published blog posts by an author. The first argument is the author ID and the second one the page of posts you want to fetch.
Fetches all published pages. The response is paginated, starting on page 1. You can pass the desired page as a number to the function. Keep in mind that the function only fetches the basic data of a page and no details such as its elements.
Filters an array of Caasy elements by a given custom element ID. The function returns an array that contains all elements that have the given custom ID.