NTYAirData

Created: 2014-05-19 03:13
Updated: 2014-09-08 05:19
License: mit

README.md

NTYAirData

Version Platform

Installation

NTYAirData is available through CocoaPods, to install it simply add the following line to your Podfile:

pod "NTYAirData"

Usage

NTYAirDataServer *server = [[NTYAirDataServer alloc] initWithManagedObjectContext:context];
[server addResource:[NTYResourceDescription resourceForEntityName:@"User" resourceKey:@"name"]];
[server addResource:[NTYResourceDescription resourceForEntityName:@"Article" resourceKey:@"uid"]];
[server start];

By default, a HTTP server runs in your application at 80 port on devices or 8080 port on simulators. You can change the port by startWithPort:.

NTYResourceDescription describes a resource served by the server. resourceKey is used to identify a resource because objects managed by Core Data have no primary key.

RESTful API

The server has RESTful APIs for data managed by Core Data. If your application have User entity, the server will have below APIs.

GET    /users.json               - get the collection of user objects
GET    /users/:resource_key.json - get an user object identified by :resource_key
POST   /users.json               - create a new user object

The server will response data in the format of JSON like below.

$ curl http://192.168.1.10/users.json
[
  {
    "age": 18,
    "name": "Alice"
  },
  {
    "age": 19,
    "name": "Bob"
  },
  {
    "age": 20,
    "name": "Charlie"
  }
]
$ curl http://192.168.1.10/users/Alice.json
{
  "age": 18,
  "name": "Alice"
}
Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more