- Notifications
You must be signed in to change notification settings - Fork39
*API v2 JavaScript client for Cosmic. See important message in README
License
cosmicjs/cosmicjs-node
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This package connects to projects on the old Cosmic dashboard and API v2 only. To connect to projects on thenew Cosmic dashboard and API v3 use theCosmic JavaScript SDK.
Cosmic is aheadless CMS (content management system) that provides a web dashboard to create content and an API toolkit to deliver content to any website or application. Build nearly any type of content model using our admin dashboard then deliver your content powered by ourreliable infrastructure and global CDN.
Avoid the pain of building, configuring, and maintaining your own CMS infrastructure. Cosmic has all of the features you need out of the box optimized and ready. Plug into Cosmic, save time, and launch your content-powered apps faster.
🛠️ Powerful content modeling
🔍 Flexible queries
⚡ Customized API response
🌎 Localization
🎨 Image optimization
…and more!See more features →
Start by going to https://www.cosmicjs.com, create yourfree account and set up a project. You can get started from scratch, or start with apre-built template. Then follow the steps below to use this NPM package.
Install the Cosmic NPM module:
pnpm install cosmicjs# ORyarn add cosmicjs# ORnpm install cosmicjs
Import Cosmic into your app:
constCosmic=require("cosmicjs")constapi=Cosmic()
In yourCosmic admin dashboard go toYour Bucket > Settings > API Access and get your Bucket slug and read key then set the variables in your app to connect to your Bucket:
constbucket=api.bucket({slug:"YOUR_BUCKET_SLUG",read_key:"YOUR_BUCKET_READ_KEY",})
Delivering content to your app is simple using theobjects.find
method.
Get multiple Objects
Use theobjects.find
method and set thetype
property to any Object Type slug. Additional options noted below.
constdata=awaitbucket.objects.find({type:"products"// Object Type slug}).props("title,slug,metadata")// response properties.limit(10)// number of Objects to be returned
Get single Object by slug
Use theobjects.find
method and set theslug
property to any Object slug.
constdata=awaitbucket.objects.find({type:"pages",// Object Type slugslug:"home",// Object sluglocale:"en",// optional, if localization set on Objects}).props("title,slug,metadata")// response properties
For more in-depth guides on getting Cosmic data into your app, you can view thesebasic query examples. When you are ready to level up, check outadvanced query examples.
The Cosmic API is fully CRUD (create, read, update, delete) capable, enabling user-generated content and file uploads. Check out theadd Object andadd media examples in the documentation.
See thefull documentation for more requests and capabilities.
For general help, please refer tothe official Cosmic documentation. For additional help, you can use one of these channels to ask a question:
- Slack (For live discussions with the Cosmic community and team)
- GitHub (Bug reports, contributions)
- Twitter (Get the latest news about Cosmic features and notifications)
- YouTube (Learn from video tutorials)
This project is published under theMIT license.
About
*API v2 JavaScript client for Cosmic. See important message in README