FeedHenry API

Coding. The fun part!

$fh.doStuff

Client API

  • Available for all major platforms
  • iOS, Android, JavaScript, Windows, Xamarin
  • Provides access to core FeedHenry functionality
  • Follows standard conventions for each environment
  • Almost zero configuration at runtime

Sample Functions

  • $fh.cloud - HTTPS communication with cloud
  • $fh.auth - Authentication via the Platform
  • $fh.sync - Sync data between client and cloud
  • $fh.forms - Manage forms based app content
  • $fh.getCloudURL - Get the URL of the Cloud App
  • $fh.sec - Encryption and key generation
  • $fh.hash - Data hashing

Configuring the SDK

  • JavaScript - fhconfig.json
  • iOS - fhconfig.plist
  • Android - fhconfig.properties
  • Windows - fhconfig.json
  • Xamarin - Platform specific (Examples)
  • Samples included in Project Templates

Configuring the SDK

  • All platforms require the same options...
  • App Title - Name of the App
  • App ID - The ID of this Client Application
  • App API KeyThe API Key of this Client Application
  • Project ID - Available on Project Settings screen
  • Connection Tag - Cloud instance to communicate with
  • Host - Your full domain URL

App ID & API Key?

Project ID?

Connection Tag?

fhconfig.json



{
  "appid": "hOes1tGp_a5JQ445PjKwyL5M",
  "appkey": "6549c1aef814b4e8bdf5d3d25194ebeee45",
  "apptitle": "My Application",
  "connectiontag": "X.Y.Z",
  "host": "https://yourdomain.feedhenry.com",
  "projectid": "hOe91u9jDDuVkuhKNKxRoqBp"
}

Getting the SDK

Using the SDK

Some Examples

JavaScript - $fh.cloud


function success (res) {
  console.log(res)
}

function fail (msg, err) {
  console.error(msg, err);
}

$fh.cloud({
  "path": "/api/v1/user/create", // URL is automatically configured
  "method": "POST", // e.g. GET, PUT, DELETE, OPTIONS
  "contentType": "application/json",
  "data": { "username": "testuser"}, // data to send to the server
  "timeout": 25000 // Timeout in milliseconds
}, success, fail);

Objective-C - FHCloudRequest

NSDictionary * headers = [NSDictionary dictionaryWithObject:
    @"application/json" forKey:@"contentType"];

NSDictionary * data = [NSDictionary dictionaryWithObject:
    @"testuser" forKey:@"username"];

NSString *mtd = @"POST";
NSString *url = @"/api/v1/user/create";

FHCloudRequest * action = (FHCloudRequest *) [FH buildCloudRequest:url 
WithMethod:@mtd AndHeaders:headers AndArgs:data];
  [action execAsyncWithSuccess:^(FHResponse * actRes){
    NSDictionary * resData = actRes.parsedResponse;
    // ...
  } AndFailure:^(FHResponse * actFailRes){
    // Errors are in the rawResponse string
    NSLog(@"Failed to read tweets. Response = %@", actFailRes.rawResponse);
  }
];

Java - FHCloudRequest

Header[] headers = new Header[1];
headers[0] = new BasicHeader("contentType", "application/json");

FHCloudRequest request = FH.buildCloudRequest(
    "/api/v1/user/create", 
    "POST",  
    headers,
    new JSONObject().put("username", "testuser")
);

request.executeAsync(new FHActCallback() {
  @Override
  public void success(FHResponse res) {
    try{
      // process response data
    } catch(Exception e){
      Log.e(TAG, e.getMessage(), e);
    }
  }
  @Override
  public void fail(FHResponse res) {
    Log.e(TAG, res.getErrorMessage(), res.getError());
  }
});

.NET - FH.Cloud

IDictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("contentType", "application/json");

IDictionary<string, object> data = new Dictionary<string, object>();
data.Add("username", "testuser");

FHResponse response = await FH.Cloud("/api/v1/user/create", "POST", headers, data);

if(null == response.Error)
{
  //no error occured, the request is successful 
  string rawResponseData = response.RawResponse;
  //you can get it as JSONObject (require Json.Net library)
  JObject resJson = response.GetResponseAsJObject();
  //process response data
}
else
{
  //error occured during the request, deal with it. 
  //More infomation can be access from response.Error.InnerException
}

$fh.doStuff(opts, callback)

Cloud API

  • Pure Node.js API
  • Written with Node.js conventions in mind
  • Provides middleware for ExpressJS
  • Zero configuration calls for complex tasks

Sample Functions

  • $fh.act - HTTP communication with other Cloud Apps
  • $fh.db - Zero config storage with Mongo
  • $fh.cache - Zero config caching with Redis
  • $fh.stats - Create unique statistics
  • $fh.forms - Interact with Forms API
  • $fh.sync - Configure Mongo collections for Sync
  • $fh.sec - Encryption and key generation
  • $fh.hash - Hashing API
  • $fh.push - Interact with Urban Airship

$fh.db - Example

// Get a reference to the cloud API
var $fh = require('fh-mbaas-api');

// Called when the operation completes
function createCallback (err, res) {
  if (err) {
    console.log(err);
  } else {
    console.log(res);
  }
}

// Create a user in the Users Mongo collection
$fh.db({
  act: 'create',
  type: 'Users'
  fields: {
    name: 'John Doe',
    age: 32
  }
}, createCallback);

ExpressJS Middleware

var $fh = require('fh-mbaas-api');
var app = require('express')();
var mbaasExpress = $fh.mbaasExpress();
var port = process.env.FH_PORT || process.env.VCAP_APP_PORT || 8001;

// list the endpoints which you want to make securable here
var securableEndpoints = ['hello'];

// Note: the order which we add middleware to Express here is important!
app.use('/sys', mbaasExpress.sys(securableEndpoints));
app.use('/mbaas', mbaasExpress.mbaas);

// Note: important that this is added just before your own Routes
app.use(mbaasExpress.fhmiddleware());

Add custom routes here...

// Important that this is last middleware added!
app.use(mbaasExpress.errorHandler());

var server = app.listen(port, function() {
  console.log("App started at: " + new Date() + " on port: " + port);
});

Questions?

FeedHenry API/SDK

By Evan Shortiss

FeedHenry API/SDK

Quick guide to the FeedHenry API/SDK for client and cloud apps.

  • 1,116