JavaScript (Legacy)

Connect your HTML browser applications to Gitana

Latest Version
Version undefined
Date

The Gitana JavaScript driver can be dropped into any web or mobile application running in the browser, within Node.js or any of a host of web frameworks including jQuery, Vue.js, Next.js, Nuxt and many others.

Loading the Driver

You can load the driver into your web application in one of three ways:

In the Browser

<script type="text/javascript" src="gitana.min.js"></script>
<script>
    Gitana.connect({...}, function() {
        // ...your code
    });
</script>

Using AMD

define(["gitana"], function(Gitana) {
    Gitana.connect({...}, function() {
        // ...your code
    });
});

Using Common JS

var Gitana = require("gitana");
Gitana.connect({...}, function() {
    // ...your code
});

Installation

You can get the Gitana JavaScript driver using Bower, NPM, via a direct download or you can load it from the Cloud CMS CDN.

Install using Bower

bower install gitana

Install using NPM

npm install gitana

Direct Download

The Gitana driver comes wrapped with a shim to auto-detect the presence of an AMD and CommonJS loaders. This allows it to be loaded into a segmented namespace via tools like RequireJS within the browser or Node.js on the server-side. The driver is entirely standalone and has no external dependencies.

Getting Started

To connect to Gitana, you first need to have a set of API Keys. In Gitana, API Keys consists of a client key/secret and a user key/secret. You pass these keys into the Gitana.connect method as a JSON object.

You can create as many API Keys as you would like. The basic process for getting your own keys is described in the API Keys. Give that a shot and when you're done, you should have the following:

  • clientKey
  • clientSecret
  • username
  • password

You can then connect to Gitana using a code block like the one shown below. Make sure to plug in the values for clientKey, clientSecret, username and password from the API Keys that you generate.

Gitana.connect({
"clientKey": "{clientKey}",
"clientSecret": "{clientSecret}",
"username": "{username}",
"password": "{password}",
"baseURL": "https://api.cloudcms.com"
}, function(err) {

    // here is some sample code of what we might then do

    // create a repository, get master branch
    this.createRepository().readBranch("master").then(function() {

        // create a few nodes
        this.createNode();
        this.createNode({ "title": "My second node" });
        this.createNode({ "title": "My third node", "name": "boo" });

        // query for nodes
        this.queryNodes({ "name": "boo" }).count(function(count) {
            console.log("count = " + count); // 1
        });
    });

    // create then delete a domain
    this.createDomain({
        "title": "Users and Groups"
    }).del();

});

Documentation

The JavaScript driver is a very powerful library that provides access to 100% of the capabilities of Gitana from a programmatic perspective. It is therefore important to first familiarize yourself with the concepts presented in the Gitana Documentation.

You should familiarize with the Gitana REST API which covers HTTP-level information about all of the methods and operations available within Gitana.

Check out our Gitana JavaScript Cookbook for recipes and examples using the JavaScript Driver.

Fork the Code

The Gitan JavaScript driver is 100% open-source (Apache 2.0) and so you're free to fork it, extend it and dig into it to learn about how it works. We provide hundreds of test files and thousands of unit tests within that demonstrate various code operations. It's really cool.

Bugs / Problems

If you run into a bug, please create an issue so that we can look at it.
For production support, please contact us at support@gitana.io or call us directly.

Support and Terms of Use

The JavaScript driver is free to use in your applications and projects. It is fully supported by Gitana.