cosmicjs-browser

The official Javascript client for Cosmic JS on the browser. This module helps you easily add dynamic content to your website or application

Usage no npm install needed!

<script type="module">
  import cosmicjsBrowser from 'https://cdn.skypack.dev/cosmicjs-browser';
</script>

README

Cosmic JS Logo

Cosmic JS Client for the browser

Getting started

Go to https://cosmicjs.com, create an account and setup a bucket.

Install

npm install cosmicjs-browser

Usage

/* Configure
================================ */
var config = {};
config.bucket = {
    slug: 'client-example',
    read_key: '', // add read_key if added to your Cosmic JS bucket settings
    write_key: '' // add write_key if added to your Cosmic JS bucket settings
};

/* Get bucket
================================ */
Cosmic.getBucket(config, function(err, bucket){
                
    // do something with the bucket

});

/* Get objects
================================ */
Cosmic.getObjects(config, function(err, objects){
                
    // do something with objects

});

/* Get media
================================ */
Cosmic.getMedia(config, function(err, media){
            
    // do something with media

});

/* Add object
================================ */
var object = {
    "write_key": config.bucket.write_key,
    "type_slug": "pages",
    "title": "Test Title",
    "content": "Test Content"
};

Cosmic.addObject(config, object, function(err, object){
    
    // say hi to your new object
    
});

/* Edit object
================================ */
var object = {
    "write_key": config.bucket.write_key,
    "slug": "test-title",
    "type_slug": "pages",
    "title": "New Title",
    "content": "New Content"
};

Cosmic.editObject(config, object, function(err, object){
    
    // say hi to your edited object

});

/* Delete object
================================ */
var object = {
    "write_key": config.bucket.write_key,
    "slug": "test-title"
};

Cosmic.deleteObject(config, object, function(err, object){

    // say goodbye to your object

});