Developer Docs

JavaScript Web Guide

Understanding Data

How Data is Handled

Inside a Flybase app, we have collections, which contain data.

We store all data inside a collection as JSON objects. When we add a new record to a collection, it becomes a document in the existing JSON structure.

For example, if we added a column named furbies to the kaitlyn user under the users collection, our data looks as follows:


	{
		"users": {
			{
				"_id": "uniquedocid-1",
				"username": "kaitlyn",
				"friends": { "jacob": true },
				"name": "Kaitlyn",
				"furbies": { "cocoa": true, "totoa": true }
			},
			{
				"_id": "uniquedocid-2",
				"username": "jacob",
				...
			},
			{
				"_id": "uniquedocid-3",
				"username": "caleb",
				...
			}
		}
	}
			
Creating a Flybase Object Reference

To read and write Flybase data, we first create a reference to the data store.


	var flybase = new Flybase("74k8064f-cd6f-4c07-8baf-b1d241496eec", "web", "posts");
			

A Flybase object reference consists of three items:

  1. Your API Key, represented by: 74k8064f-cd6f-4c07-8baf-b1d241496eec
  2. The slug of a Flybase app that has been created in your account: web
  3. Finally, the name of a data collection, in this example: posts

Data inside a Flybase app is organized by collections, if you are familiar with SQL tables, then this is similar to tables.

Apps must be created inside your Flybase dashboard, but if you call a collection that does not exist already then it will get created the first time you save data to it.

Flybase provides a Dashboard, which displays a visual representation of the data and provides tools for simple administrative tasks.

Passing JSON Web Tokens

If you don't want to pass your API key every time then you can also pass a JSON web token.

This can be generated by passing the following POST query:


	curl -X POST https://api.flybase.io/create-token/YOUR-API-KEY
			

This will return a JSON object with id_result as the key, copy the contents of id_result to use elsewhere.

Then you can pass the JSON token rather than your API key:


	var flybase = new Flybase("token:MYJWTTOKEN", "web", "posts");
			

Anytime token: is seen, Flybase will assume this is a JWT token and will retrieve your API Key from inside that, this helps secure your API key if you decide you'd rather not share it.

That's it! Now we're ready to start writing data to Flybase which we'll cover in the next section.