Blog
Published On: 2024-10-01 by Wiseman Fernandes
Setting Up a Bucket on Cosmic JS: A Step-by-Step Guide

Introduction

Cosmic JS is a headless CMS that makes it easy to manage and deliver content for your web applications. One of its core features is the ability to create and manage buckets, which are essentially containers for your content.


Prerequisites

  • A Cosmic JS account
  • Basic understanding of content management systems

    Steps
    1. Create a Bucket

      • Log in to your Cosmic JS dashboard.
      • Click on the "Create Bucket" button.
      • Give your bucket a name and choose a slug. The slug will be used in your API endpoints.
      • Select a plan that suits your needs.
      • Click "Create Bucket".
    2. Define Content Types

      • Once your bucket is created, you'll need to define the structure of your content. This is done by creating content types.
      • Click on the "Content Types" tab within your bucket.
      • Create a new content type and give it a name and a slug.
      • Define the fields for your content type. You can choose from various field types like text, number, date, boolean, and more.
      • Click "Save" to create your content type.
    3. Create Content

      • Now that you have content types, you can create content items within those types.
      • Click on the "Content" tab within your bucket.
      • Select the content type you want to create content for.
      • Fill in the fields with your desired content.
      • Click "Save" to create your content item.
    4. Access Content Using the API

      • Cosmic JS provides a RESTful API to access your content. You can use the API to fetch, create, update, and delete content items.
      • The API endpoint for a bucket is typically in the format: https://api.cosmicjs.com/v2/{slug}.
      • Replace {slug} with the slug of your bucket.
      • You'll need to use your Cosmic JS API key to authenticate your requests.

Example API Request:

JavaScript

fetch('https://api.cosmicjs.com/v2/my-bucket', {
  headers: {
    'Authorization': 'Bearer your_api_key'
  }
})
.then(response => response.json())
.then(data => console.log(data));


Conclusion

By following these steps, you can create a bucket on Cosmic JS, define content types, and manage your content using the API. Cosmic JS provides a flexible and user-friendly way to manage your content for web applications.

API Development