<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=433889730767799&amp;ev=PageView&amp;noscript=1">

How Do I Use Macrometa?

Getting Started With Global Apps & APIs

Build a JAMstack, SPA Web App With a Multi Region, Distributed Backend In 15 Minutes

Sign Up For A Free Account

Building an address book app - serving data from multiple global locations around the world

Let’s create the backend for a simple Address Book app in the next few minutes. Our address book app will be run globally distributed with local read-write latencies on Macrometa’s fast data platform.  
I have highlighted the words next few minutes in the above paragraph because typically doing the same exercise without using Macrometa’s platform will take months to build it (assuming the team has necessary expertise). Don’t take my word though. Verify it for yourself.
Note: You need an account with Macrometa’s Fast Data platform to build the backend for the app. If needed, you can get a free developer account here.
Building the geo-distributed backend engine for our app involves 3 steps:
  • Creating a geo-fabric to distribute our database and streams across worldwide locations we want to run our backend at
  • Creating a collection (like a table in SQL) and creating queries for CReate, Update and Delete (CRUD)
  • Exposing and consuming the CRUD queries as RESTful API endpoints 
Step-1: Creating a geo fabric - a database that spans two or more global regions

Use your tenant credentials to login at https://gdn1.macrometa.io

Once you login, you should see a dashboard with a map showing all the global locations provisioned for you to use. 

The pin icons on the map represent all the locations to which the data will be automatically replicated, synchronized and stored in a deterministic manner. Applications can read and write locally from all these locations without waiting on synchronization for updates from other locations.  By default all data will be stored in all locations on your map. However you can create specific geo-fabrics if you want to use a subset of the locations provided. 

Step-2: Create an Address Book Collection
Collections in Macrometa’s are like tables in an RDBMS database. A collection contains zero or more documents. Macrometa is schema-less. You can read more about various data models supported by the database here.
Lets start by clicking the COLLECTIONS menu entry, then the Add Collection tile. Give it a name, e.g. addresses, leave the other settings unchanged (we want it to be a document collection) and Save it.
A new tile labeled "addresses" should appear. You can click to open (it will be empty since we have not stored any data in it yet).
Note: The collection "addresses" will automatically be created in all locations where you see pin in the map.
Step-3: Generate CRUD REST API (RESTQL)
To store addresses in our address book app, we will use the following document format (or schema) for each contact:
  "firstname": "John",
  "lastname": "Doe",
  "email": "john.doe@macrometa.io",
  "zipcode": 56703
Click the QUERIES menu entry to open C8QL query editor. Then create the query shown in the screenshot to the right.
Let's execute the query to make sure it works correctly. Do this by clicking on the "Execute"  button in blue. 
Automatic REST API creation for queries
Let’s save the query with name addAddress. This query then automatically will be available as a REST end point for execution globally by its name addAddress.  In short, within a second you have a globally distributed backend service for this functionality in your app. Simple right?
Let’s write queries for the other server side capabilities we need in our AddressBook app. Save them with relevant names as follows:
Name: addAddress
INSERT { firstname: @firstname, 
        lastname: @lastname, 
        email: @email, 
        zipcode: @zipcode }
   INTO addresses
Name: getAddresses
FOR address IN addresses
    RETURN address
Name: updateEmail
UPDATE { _key: @key }
  WITH { email: @email }
  IN addresses
  Name: removeAddress
REMOVE { _key: @key} 
  IN addresses
You can read more about how to write C8QL queries here.
Click the SUPPORT menu entry and open the API Browser. Scroll down and to see RESTQL api.
You can execute RESTQL API from anywhere in the world. The Macrometa fast data platform will take care of intelligently routing the request to the location closest to your app, and return results from that location.
To see Macrometa in action, let’s execute our getAddresses API using the curl command.  Click on SUPPORT, scroll down to RESTQL, and select the POST option to "Execute restql by name".  After adding your tenant name, fabric name, and query name (in this case, getAddresses), select Execute and you'll see the Curl syntax is built for you.
In the screenshot to the right, Macrometa’s  platform routed the request and executed in LosAngeles, US datacenter as that is closest to my current location (Macrometa is based in Palo Alto).