Once you're signed up for CosMoS, the first thing you want to do as a developer is to create a new Application. In this case Application does not necessarily mean an IOS or Android App. It can merely be seen as a project. So it might be a PHP Application, a Java Application, a Python Application and so on. It can even be an Application that will be accessed from multiple platforms; if for instance your Node WebApp has the same content as your Android App.
Give your Application a Name and optionally set a Thumbnail URL, just to make your clients recognise the Application. This Thumbnail has no other use than that.
When you've created the Application a private key will be displayed, but watch out this key is only shown once and will not live on our servers. Copy the key directly into your code or into a separate file, this choice is depending on your programming language.
Well done! You've successfully created an Application.
Start making new Content sections. Give them a Name, an API-Name and specify the Type of Content. The API-Name must be given as the parameter when you want to fetch this Content using one of our dependencies.
To integrate CosMoS into your project, you'll need to download our dependencies for your desired language. An easy way to install CosMoS is described below for all the currently supported programming languages. Choose the one your application is written in and get started!
CosMoS uses Composer to install its dependencies. Make sure you've installed Composer before going on to the next step.
Download CosMoS and its dependencies by running the following command in the root of your project:
# Please use dev-master since CosMoS is still in beta. composer require "cosmos-cms/cosmos-php:dev-master"
Now that you've installed required dependencies, take a look at the next steps to start using CosMoS.
To utilize CosMoS in each of your PHP files, it is recommended to use some kind of bootstrap or init file. This file would contain all the setup needed for CosMoS. Simply include that file in every page you want to use CosMoS at. Your bootstrap file should consist of the following lines to connect to our encrypted API:
<?php // Require the autoload.php file that's generated by Composer require 'vendor/autoload.php'; // Use the correct namespace for CosMoS use Cosmos\Cosmos; // Create a new instance of the Cosmos object $cosmos = new Cosmos(); // Setup the path to your private key // This key was only displayed once when your Application was created $cosmos->setPrivateKey('key.txt'); // Set your API key, which can be found in your Application Settings $cosmos->setApiKey("9d25d2d0053b22fdfa1b4becdfdfa9a4"); // Give up the path for the folder where your cache files will be stored $cosmos->setCachePath('cache'); // You can set a custom refresh rate in seconds, default is 1 day $cosmos->setRefreshRate(60);
The examples below will show you how to fetch your content from CosMoS' encrypted API. If your cached content is younger than the given refresh rate, the cached contents will be returned.
Since you've already created a bootstrap or init file, it's very easy to fetch from our API.
<?php // Require your bootstrap or init file require 'init.php'; // Display your content // In this case the content with API name 'welcome' is fetched from the API or cache echo $cosmos->get('welcome'); // Display your content's title or type echo $cosmos->get('welcome')->name(); echo $cosmos->get('welcome')->type(); // Returns either 'html' or 'plain'