View on GitHub

Jest

Put your Restkit mapping code to json files

Download this project as a .zip file Download this project as a tar.gz file

jest

Why did I make this?

RestKit is a great and well design framework and reduce alot of your code when you need to work with your server's REST api. However, your server REST api need to be well designed and the responses should be well-structure JSON/XML data.

In some of my past project, when I had to work with a server api that didnt have that quality, writing RestKit mapping is as time consuming as write code to directly parse the raw response. It's even worse in some case that server doesnt have a consistent vocabulary (using different keys for the same data property). In such the case, you most likely have to write/rewrite different object mappings for each API points.

Here are some reason that make writing RestKit mapping a painful task:

  1. Response is a big-flat object. All the key-value pairs is packed in a big-flat object
  2. Inconsistent key: use different keys for the same data
  3. Inconsistent data format

How Jest may release your pain?

Instead of tangling my code with object mapping, with Jest, i can put all of my mapping into json file. Object mappings will be written in expressive json objects, so that you can put all the mess out of your source code into json. Because of the expressiveness of the description file, writing those mappings will less painful than writing in code.

Here is a quick example:

{
    "responseDescriptors": [
        {
            "requests": [
                {
                    "path": "/v2/venues/search",
                    "keyPath": "response.venues",
                    "root-map-ref": "venueMap",
                    "statusCodes": ["2XX"]
                }
            ],
            "maps": [
                {   
                     "id": "venueMap",
                     "targetName": "JestExamples.Venue",
                     "attributes": ["name"],
                     "relationships" : [
                        {"from" : "location", "to" : "location", "map-ref" : "locationMap"},
                        {"from" : "stats", "to" : "stats", "map-ref" : "statsMap"}
                     ]

                },
             {
                 "id": "locationMap",
                 "targetName": "JestExamples.Location",
                 "attributes": ["address", "city", "country", "crossStreet", "postalCode", "state", "distance", "lat", "lng"]
             },
             {
                 "id": "statsMap",
                 "targetName": "JestExamples.Stats",
                 "attributes": {
                     "checkinsCount" : "checkins",
                     "tipsCount" : "tips",
                     "usersCount" : "users"
                 }
             }

            ]
        }
    ]
}

Jest and Restkit

Jest can describe mapping supported by Restkit:

Take a look at Examples.md to see how to handle most of common cases.

How to integrate ?

  1. Use cocoapod: pod 'jest', '~> 0.1'
  2. Check out this repo
  3. Download release zip file