Giter Site home page Giter Site logo

datakit's Introduction

Don't reinvent the wheel every time you need a web backend for your apps, add one with DataKit in minutes!

Just spin up a server with node and MongoDB installed, integrate the SDK into your app and you are ready to go! Have a look at the SDK Docs. DataKit requires iOS 5 and ARC.

Author: Erik Aigner @eaignr

Server Configuration

Make sure you have node with npm and MongoDB running on your server. Setup your node project and install DataKit.

npm install datakit

Then create a file run.js (or any other name you prefer) containing the following:

require('datakit').run({});

Now start your node app and DataKit will present the following warning

WARN:  No secret found in config, generated new one.
       Copy this secret to your DataKit iOS app and server config!

       66e5977931c7e48aa89c9da0ae5d3ffdff7f1a58e6819cbea062dda1fa050296 

       Terminating process.

Copy the newly generated secret and put it in your DataKit config. Now you can also specify additional config parameters. Although only the secret parameter is required, you should also specify a custom salt.

require('datakit').run({
  'secret': '66e5977931c7e48aa89c9da0ae5d3ffdff7f1a58e6819cbea062dda1fa050296',
  'salt': 'mySecretSauce',
  'mongoURI': 'mongodb://<user>:<pass>@<host>:<port>/<dbName>',
  'port': 3000, // The port DataKit runs on
  'path': 'v1', // The root API path to append to the host, defauts to empty string
  'allowDestroy': false, // Flag if the server allows destroying entity collections
  'allowDrop': false, // Flag if the server allows db drop
  'cert': 'path/to/cert', // SSL certificate
  'key': 'path/to/key', // SSL key
  'express': function (app) { /* Add your custom configuration to the express app */}
});

Integrate the SDK

Link to DataKit and import <DataKit/DataKit.h>. Now we only need to configure the DataKit manager and we are almost there (this needs to be done before any other DataKit objects are invoked, so the app delegate would be a good place to put it).

[DKManager setAPIEndpoint:@"http://localhost:3000"];
[DKManager setAPISecret:@"66e5977931c7e48aa89c9da0ae5d3ffdff7f1a58e6819cbea062dda1fa050296"];

Start Coding

Here are some examples on how to use DataKit. This is in no way the complete feature set, please look at the documentation. You can throw almost anything at DataKit.

Classes:

Entites

// Saving
DKEntity *entity = [DKEntity entityWithName:entityName];
[entity setObject:@"Erik" forKey:@"name"];
[entity setObject:@"Aigner" forKey:@"surname"];
[entity setObject:imageData forKey:@"avatar"];
[entity setObject:[NSNumber numberWithInteger:10] forKey:@"credits"];
[entity save];

Queries

DKQuery *query = [DKQuery queryWithEntityName:@"SearchableEntity"];
[query whereKey:@"text" matchesRegex:@"\\s+words"];

NSArray *results = [query findAll];

Files

// Saving
DKFile *file = [DKFile fileWithName:@"BigFile" data:data];
[file save];

// Loading
DKFile *loadMe = [DKFile fileWithName:@"SomeFile"];
[loadMe loadDataInBackgroundWithBlock:^(BOOL success, NSData *data, NSError *error) {
  // Invoked on finish
} progressBlock:^(NSUInteger bytes, NSUInteger totalBytes) {
  // Track progress
}];

Donate if you like it!

Click here to lend your support to: DataKit and make a donation at www.pledgie.com !

TODO

  • Add some sort of ACL and user authentication instead of shared secret
  • Add DKChannel class for push notifications and async messaging

datakit's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.