Tutorial - Hello, World! | Chino.io

Introduction

In this tutorial we'll see how the basic storage of data works with Chino.io.

This tutorial is available for the following programming languages: {{languages.join(", ")}}. In the setup you can change programming language.

Use Case

We are going to create a simple Schema for a Document. Then we will learn how to create, read, update and delete data, in the shape of Documents.

Resources

We are going to use the following resources:

  • a Document, where data are stored in Chino.io,

  • a Schema, which defines the structure of the Document,

  • a Repository, a container for Schemas.

Select language:

Register to Chino.io 

To register to our service go to console console , fill in the form, confirm the email and access.

Note: You can use Chino.io test environment for free.

Write here your customer ID and Key

Here you can write your customerId and customerKey to have them filled out in the code. It's just for the purpose of the tutorial.

Click on the following button to add the Collection with the calls of this tutorial in Postman.
Postman will automatically set the values inserted in this page in the environment variables.

Note: if you want to add an environment in Postman, please fill the customer_id and customer_key in the box above.

Setup development environment

Install library

First thing to do is to setup an environment (optional) and install the SDK (mandatory)

(sudo) pip install git+https://github.com/chinoio/chino-python.git

Install library

First thing to do is to setup an environment (optional) and install the SDKs (mandatory)

There are two ways to install the SDKs:

If you're using Maven, then edit your project's pom.xml and add this:

    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>

    <dependency>
        <groupId>com.github.chinoio</groupId>
            <artifactId>chino-java</artifactId>
        <version>1.0</version>
    </dependency>

If you're using Gradle, then edit your project's build.gradle and add this:

    allprojects {
        repositories {
            ...
            maven {
                url 'https://jitpack.io'
            }
        }
    }

    dependencies {
        // ...
        compile 'com.github.chinoio:chino-java:1.0'
    }

The other method is building the SDKs from source:

git clone https://github.com/chinoio/chino-java.git
    cd chino-java
    ./gradlew build

The output will be in build/

And if you want a "fat jar" with all the dependencies inside use the following commands:

git clone https://github.com/chinoio/chino-java.git
    cd chino-java
    ./gradlew build shadowJar

In order to perform network operations your Android manifest must include the following permissions:

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

You can use Postman to try our rest API. We provide a Collection, to be imported in Postman, which allows you to easily test every call in this tutorial.

You can download Postman at this link .

SDK distribution

You can integrate the CHINO.io Swift SDK into your project using one of several methods.

CocoaPods

To use CocoaPods, a dependency manager for Cocoa projects, you should first install it using the following command:

$ gem install cocoapods

Then navigate to the directory that contains your project and create a new file called Podfile. You can do this either with pod init, or open an existing Podfile, and then add

pod 'ChinoOSXLibrary', :git => 'https://github.com/chinoio/chino-ios.git', :tag => '1.0'

to the main loop. Your Podfile should look something like this:

use_frameworks!

target '<YOUR_PROJECT_NAME>' do
    pod 'ChinoOSXLibrary', :git => 'https://github.com/chinoio/chino-ios.git', :tag => '1.0'
end

Then, run the following command to install the dependency:

$ pod install

Once your project is integrated with the CHINO.io Swift SDK, you can pull SDK updates using the following command:

$ pod update

Initialize SDK

First thing to do is to initialize our SDK.

We now have access to the SDK that wraps all the calls that Chino.io API offers.

Note

Network operations in Android cannot be performed in the main UI Thread. You have to wrap the API calls in an AsyncTask :

  • Start the AsyncTask passing all the required parameters in an array: execute(params)

  • Perform your call inside the method doInBackground, which is executed asynchronously

  • Elaborate the results - if it can be done in the async method - and eventually return them

  • Update your local values and the UI in the method onPostExecute, which is executed on the UI thread.


{{ androidCode ? "Hide" : "Show" }} example

Create a subclass of AsyncTask:

Then, from your Activity or class trigger the task like this:

TextView mTextView = findViewById(R.id.myTextView); String[] params = { "68e0cfb0-bb2b-4cf1-b73a-f83e262f2ce8", "a311dea9-9486-4a05-8050-a53409b00aa4", "0dbe2671-7f74-4739-be1d-7a0db303f6bb" }; new ChinoAsyncTaskExample(mTextView).execute(params);

Create a Repository

On Chino.io, each Document is stored in a Repository, so we start by creating a new one.

This can be done in the console or via the API.

This can be done in the console or via the API, with Postman: just select the first call in the Collection and press "Send".

We will set the Repository's description to hello world tutorial.

Once created we copy the (write here your repository_id) so that we can use it as a constant in the code examples.

Create a Schema

A Schema represents the structure of the Documents that we store in Chino.io. It defines the fields of a Document, the type of those fields and whether or not they should be indexed for search.

We will define a simple Schema for this tutorial:

  • title (string (indexed) -): a brief title for the document

  • content : (text (not indexed) -): the document actual content

Many more data types can be defined, such as dates and integers. Learn more in the documentation page for Schemas.

We create a new Schema in our Repository and name it base_schema:

Once created, copy the schema_id

Create and Read a Document

Now we can create a simple Document and store it in Chino.io:

Content:

API call:

Chino.io will return a document_id, which can be used to change or delete our new file. Before we proceed, copy here the document_id of the new Document

With the document_id we are able to fetch from Chino.io the content of the Document:

Update a Document

You can change the content of your Documents anytime. You just need to know your document_id, which can be easily retrieved by searching one of the indexed fields. We won't cover the Search functions of Chino.io here, but you can read more about it in the Chino.io docs .

Since we have stored our document_id, we can change the Document's content to the following:

Delete a Document

Finally, we will delete the Document, which can be done easily if you know the document_id:

In the Postman collection for this tutorial you will find also some calls to delete the Schema and the Repository.

Note: Once a document has been deleted from Chino.io, there is no way to recover it.

Summary

We have seen how to perform basic operations to store, update and delete Documents on Chino.io.

Note