Livebase™ offers a built-in REST API, designed to enable integration between the Cloudlets and external systems via REST calls. The example provided here has the purpose to show how to use the REST interface automatically included in each Cloudlet created in your Livebase™ account. For more details please refer to our documentation.
Introduction
In this sample an user named John Ford (username john.ford) has created a new Cloudlet named WebStore.
John has built an application for managing data of a Web store. The application model is depicted in the following screenshot.
1. Accessing the Cloudlet
Let's suppose that we want to access the REST interface of our application. In order to do that we make a GET request to the base URI of the REST interface, that in our case is https://77.43.4.36/john.ford/WebStore/rest. Within this call we have used HTTP basic authentication over TLS. The username and password must be those of a Cloudlet member.
GET https://77.43.4.36/john.ford/WebStore/rest Accept: application/json
{
"name": "WebStore",
"applications": [
{
"localizedName": "Sales",
"name": "Sales",
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales"
},
{
"localizedName": "Warehouse",
"name": "Warehouse",
"uri": "https://77.43.4.36/john.ford/WebStore/rest/warehouse"
}
],
"uri": "https://77.43.4.36/john.ford/WebStore/rest"
}
2. Accessing an application within the Cloudlet
Let's access the application named Sales. To do this, we make a GET call on the corresponding URI.
GET https://77.43.4.36/john.ford/WebStore/rest/sales Accept: application/json
{
"classes": [
{
"localizedName": "Customer",
"name": "Customer",
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/customer"
},
{
"localizedName": "Invoice",
"name": "Invoice",
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/invoice"
},
{
"localizedName": "Order",
"name": "Order",
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/order"
}
],
"localizedName": "Sales",
"name": "Sales",
"cloudletUri": "https://77.43.4.36/john.ford/WebStore/rest",
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales"
}
3. Accessing a class within the application
The attribute classes contains the list of the classes that can be accessed through the application. As an example let's access to the Invoice class.
GET https://77.43.4.36/john.ford/WebStore/rest/sales/invoice Accept: application/json
{
"localizedName": "Invoice",
"name": "Invoice",
"objects": [
{
"id": 1001,
"lastUpdate": 1328094872000,
"attributes": [
{
"localizedName": "Created on",
"name": "__createdon",
"value": "2012-02-01T11:14:32+00:00"
},
{
"localizedName": "Number",
"name": "number",
"value": 1
}
],
"partRoles": [
{
"localizedName": "Orders",
"name": "orders"
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/invoice/1001/orders"
}
],
"associatedRoles": [
{
"localizedName": "Customer",
"name": "customer",
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/invoice/1001/customer"
"associableUri": "https://77.43.4.36/john.ford/WebStore/rest/sales/invoice/1001/customer/associable",
}
],
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/invoice/1001"
},
{
"id": 1002,
"lastUpdate": 1328094872000,
"attributes": [
{
"localizedName": "Created on",
"name": "__createdon",
"value": "2012-02-01T11:14:32+00:00"
},
{
"localizedName": "Number",
"name": "number",
"value": 500
}
],
"partRoles": [
{
"localizedName": "Orders",
"name": "orders"
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/invoice/1002/orders"
}
],
"associatedRoles": [
{
"localizedName": "Customer",
"name": "customer",
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/invoice/1500/customer"
"associableUri": "https://77.43.4.36/john.ford/WebStore/rest/sales/invoice/1500/customer/associable",
}
],
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/invoice/1002"
}
],
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/invoice",
"applicationUri": "https://77.43.4.36/john.ford/WebStore/rest/sales"
}
4. Getting a structured object and all its parts
Now suppose that we want to see all the orders about a specific Invoice. For example let's consider the Invoice instance whose number attribute value is equal to 1. To see all its parts we use the parameter depthLimit set to 1.
GET https://77.43.4.36/john.ford/WebStore/rest/sales/invoice/1001?depthlimit=1 Accept: application/json
{
"id": 1001,
"classUri": "https://77.43.4.36/john.ford/WebStore/rest/sales/invoice",
"lastUpdate": 1328094872000,
"attributes": [
{
"localizedName": "Number",
"name": "number",
"value": "1"
}
],
"partRoles": [
{
"localizedName": "Orders",
"name": "orders",
"objects": [
{
"id": 2001,
"lastUpdate": 1328094872000,
"partRoles": [],
"attributes": [
{
"localizedName": "ID",
"name": "__id",
"value": 2001
},
{
"localizedName": "Quantity",
"name": "quantity",
"value": 1
}
],
"associatedRoles": [
{
"localizedName": "Product",
"name": "product",
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/order/2001/product"
"associableUri": "https://77.43.4.36/john.ford/WebStore/rest/sales/order/2001/product/associable",
}
],
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/order/2001"
},
{
"id": 2002,
"lastUpdate": 1316178744000,
"partRoles": [],
"attributes": [
{
"localizedName": "ID",
"name": "__id",
"value": 2002
},
{
"localizedName": "Quantity",
"name": "quantity",
"value": 4
}
],
"associatedRoles": [
{
"localizedName": "Product",
"name": "product",
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/order/2002/product"
"associableUri": "https://77.43.4.36/john.ford/WebStore/rest/sales/order/2002/product/associable",
}
],
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/order/2002"
}
],
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/invoice/1001/orders"
}
],
"associatedRoles": [
{
"localizedName": "Customer",
"name": "customer",
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/invoice/1001/customer"
"associableUri": "https://77.43.4.36/john.ford/WebStore/rest/sales/invoice/1001/customer/associable",
}
],
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/invoice/1001"
}
5. Navigating an association from an object's part
Finally let's get the details of the Product instances associated to the order (on the role named product) whose quantity attribute value equals to 4.
GET https://77.43.4.36/john.ford/WebStore/rest/sales/order/2002/product Accept: application/json
{
"name": "Order",
"parentUri": "https://77.43.4.36/john.ford/WebStore/rest/sales/order/2002",
"objects": [
{
"id": 1501,
"lastUpdate": 1328094872000,
"partRoles": [],
"attributes": [
{
"localizedName": "ID",
"name": "__id",
"value": 1501
},
{
"localizedName": "Name",
"name": "name",
"value": "MP3 player"
},
{
"localizedName": "Description",
"name": "description",
"value": "8GB internal memory; support for MP3, OGG and AC3 codecs."
}
],
"associatedRoles": [],
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/product/1501"
}
],
"uri": "https://77.43.4.36/john.ford/WebStore/rest/sales/order/2002/product",
"applicationUri": "https://77.43.4.36/john.ford/WebStore/rest/sales"
}