X
X

Login

Login if you already have an account

LOGIN

Register

Create a new account. join us!

REGISTER

Support

Need some help? Check out our forum.

FORUM

FYI – it is easy to integrate your backend with other web services

As a Developer, I want to integrate with other web services so that I can offload the integration tasks from my client to my backend.

Many times, you may want to utilize some other web service for the purposes of backend integration. FatFractal makes this really easy.

Let’s say you want to interact with SalesForce data from your backend…

FatFractal support the Common.js standard which includes an http client that let’s you do just about anything you want.

Example:

Here is some code that interfaces to to securely retrieve some information from a SalesForce API:

var hc = require('ringo/httpclient');

exports.getQs = function() {
var loginUrl = "https://login.salesforce.com/services/oauth2/token";
var apiVersion = "v25.0";
var username = "someUsername";
var password = "somePassword";
var securityToken = "someSecurityToken";
var clientId = "someClientId";
var clientSecret = "someClientSecret";

function LoginSF(username, password, securityToken, clientId, clientSecret) {
var data = {
grant_type: "password",
client_id: clientId,
client_secret: clientSecret,
username: username,
password: password + securityToken
};
var response = JSON.parse(hc.post(loginUrl, data).content);
return response;
}

function QuerySF(instanceUrl, accessToken, queryString) {
var url = instanceUrl + "/services/data" + apiVersion + "/query";
var data = {q: queryString};

var request = {
url: url,
data: data,
method: "GET",
headers: {
Authorization: "Bearer " + accessToken
}
};

var response = JSON.parse(hc.request(request).content);
return response;
}
// perform query
var loginResponse = LoginSF(username, password, securityToken, clientId, clientSecret, true);
var instanceUrl = loginResponse.instance_url;
var accessToken = loginResponse.access_token;
var queryResponse = QuerySF(instanceUrl, accessToken, "SELECT A__c, B__c, C__c FROM D__c");

var records = queryResponse.records;
for (var i = 0; i < records.length; i++) {
// DO SOME STUFF
// E.G. RETURN SOME DATA (SERVER EXTENSION)
// OR TAKE SOME ACTION (EVENT HANDLER)
}
}

What this does is define a function that can be used with an Event Handler or as an API extension with a Server Extension that logs in to an API on SalesForce.com, retrieves an instance_url and access_token that are need to then to execute a query and retrieve a response.

Many other things can be done with this powerful client – have fun!

Kevin

FYI – FatFractal supports many many to many many relationships (huh?)!


As a developer, I want to easily add many to many relationships between my objects without join tables so that I get a rich data model without getting data-model nightmares

With FatFractal, you can create amazing relationships between your objects. One of the things that makes this particularly useful is the ability to add multiple kinds of relationships from any particular object:

Example: If in your application.ffdl file that was created when you scaffolded your app, you include the following

CREATE OBJECTTYPE Comment (profile REFERENCE /Profile, comment STRING, relatedTo REFERENCE)
CREATE COLLECTION /Comment OBJECTTYPE Comment

This provides a ubiquitous “Comment” object that has two references and a “Comment” Collection typed to contain only “Comment” objects.

First, you will see a reference to the author public profile:

profile REFERENCE /Profile

This defines a relationship for the profile member which is bound to the /Profile Collection (which happens to contain only Profile objects thus “typing” the reference).

It also includes a reference called relatedTo:

relatedTo REFERENCE

This relationship is unique in that there is no Collection specifed, and thus no Objecttype implied. This means that the relationship for the relatedTo member can be to any object in any Collection of any Objecttype – i.e. is not “typed” and not bound to any particular Collection.

So now I have a comment object that has a reference to any other object in any other collection – pretty nice! All comments can are accessible via a single collection (/Comment) which is also nice.

But – what makes this truly useful is that you can also access comments via BackReferences to an object. For example, to see all comments (of Objecttype Comment) that relates to any particular object at all (as example, supR – a SupportRequest instance):

ff.getArrayFromUri(supR.ffUrl + "/BackReferences.Comment",
function(anArrayOfComments) {
// This returns an array of "Comments" that relateTo supR!!
},
function(onError) {}
}

Where the SupportRequest object model is defined as:

function SupportRequest() {
this.clazz = "SupportRequest";
this.subject = null;
this.body = null;
this.relatedTo = null;
this.profile = null;
return this;
}

Note that the SupportRequest does not even include anything about “Comment” in its definition. This means that you add relationships easily and intuitively without the pain of onerous data models – in short without the nightmares.

Hope this spurs some ideas for your application…

For more on the background of this, see Gary’s blog here.

For more details about FFDL, see the documentation here.

For more details about Queries, see the documentation here.

For more details about References and BackReferences, see the documentation here.

Kevin

FYI – it is easy to integrate your backend with other web services (for example, SalesForce.com)

As a Developer, I want to integrate with other web services so that I can offload the integration point from my client code to my backend for better performance, security and reliablility.

Many times, you may want to utilize some other web service for the purposes of backend integration. FatFractal makes this really easy. FatFractal supports the Common.js standard which includes an http client that let’s you do just about anything you want.

Let’s say you want to interact with SalesForce data from your backend…

Example:

Here is some code that securely retrieves some information from a SalesForce API that could be used in either a Server Extension of Event Handler:

var hc = require('ringo/httpclient');

exports.getQs = function() {
var loginUrl = "https://login.salesforce.com/services/oauth2/token";
var apiVersion = "v25.0";
var username = "someUsername";
var password = "somePassword";
var securityToken = "someSecurityToken";
var clientId = "someClientId";
var clientSecret = "someClientSecret";

function LoginSF(username, password, securityToken, clientId, clientSecret) {
var data = {
grant_type: "password",
client_id: clientId,
client_secret: clientSecret,
username: username,
password: password + securityToken
};
var response = JSON.parse(hc.post(loginUrl, data).content);
return response;
}

function QuerySF(instanceUrl, accessToken, queryString) {
var url = instanceUrl + "/services/data" + apiVersion + "/query";
var data = {q: queryString};

var request = {
url: url,
data: data,
method: "GET",
headers: {
Authorization: "Bearer " + accessToken
}
};

var response = JSON.parse(hc.request(request).content);
return response;
}
// perform query
var loginResponse = LoginSF(username, password, securityToken, clientId, clientSecret, true);
var instanceUrl = loginResponse.instance_url;
var accessToken = loginResponse.access_token;
var queryResponse = QuerySF(instanceUrl, accessToken, "SELECT A__c, B__c, C__c FROM D__c");

var records = queryResponse.records;
for (var i = 0; i < records.length; i++) {
// DO SOME STUFF
// E.G. RETURN SOME DATA (SERVER EXTENSION)
// OR TAKE SOME ACTION (EVENT HANDLER)
}
}

Note the inclusion of the httpclient at the top of the source:

var hc = require('ringo/httpclient');

The rest defines a function – “getQs” that can be used with an Event Handler or as an Server Extension that logs in to an API on SalesForce.com, retrieves an instance_url and access_token that are required to then to execute a query and retrieve a response.

Many other things can be done with this powerful client – have fun!

For more information on our Server-Side Javascript SDK, see here.

For more information on Event Handlers on your backend, see here.

For more information on Server Extensions on your backend, see here.

Kevin

FYI – Permissions can be inherited from other objects (pretty slick!)

As a Developer, I want to be able to implement access control policies that are inherited from another object so that I can easily propagate access control policies within my application.

If you want to set a default permission for objects in a collection that inherit permissions from another object, it is super easy using FFDL (what is FFDL?).

Example:

Say you have a Collection of JokeBook objects with permission defaults set and another Collection of Joke objects that have a reference to a JokeBook and you would like your Joke objects to inherit their default permissions from JokeBook objects. OK – short version is that I want the permissions for a Joke to be the same as the JokeBook they refer to.

The FFDL would look something like:

# JokeBook
CREATE OBJECTTYPE JokeBook (title STRING, writers REFERENCE /FFUserGroup, readers REFERENCE /FFUserGroup)
CREATE COLLECTION /JokeBooks OBJECTTYPE JokeBook
PERMIT read:object.readers write:object.writers ON /JokeBooks

This defines a JokeBooks Collection that contains Jokebook Objects that have a title, a reference to an author, a reference to a group of users with write access named writers and a group of users with read access named readers.

# Joke
CREATE OBJECTTYPE Joke (setup STRING, punchline STRING, book REFERENCE /JokeBook)
CREATE COLLECTION /Jokes OBJECTTYPE Joke
PERMIT read:object.book.readers write:object.book.writers ON /Jokes

This defines a Jokes Collection that contains Joke Objects which have a a reference called “book” from the JokeBooks Collection:

book REFERENCE /JokeBooks
So, you will notice that read and write permissions for a Joke object are set to refer to the read and write permissions (respectively) that are defined for the JokeBook object referred to by the “book” member.

PERMIT read:object.book.readers, write:object.book.writers ON /Jokes

Voila! Now the Joke object has the same permissions as the JokeBook object – as easy as that!

Of course, this is the default setting and you can always change the access to any particular object programmatically in your application code.

Hope you find this useful!!

For more details, see the FFDL documentation here.

To see the other things you can do with permissions see here.

FYI – with FatFractal, you can specify your data is to be encrypted at rest!

As a Developer, I want to specify that my sensitive data is encrypted at rest so that my cloud application can have the highest level of security.

If you have truly sensitive data that you need to persist and would like to make sure that it is stored in encrypted form, all you have to do is add an [ENCRYPTED] flag to the FFDL for the Object Type definition within your application (currently Strings only).

Example:

CREATE OBJECTTYPE Account (name STRING, account [ENCRYPTED] STRING )

Umm, well – that’s it!

Kevin

For more details, see the FFDL documentation here.

Contact