[Django]-Developing an iOS app with a REST api backend (databased backed)

4👍

1) For ORM, iOS has Core Data that lets you build your entity and work with objects rather than SQL statements like SELECT, LEFT JOIN etc.

Don’t know about others, but this is how I usually do it:

1) App makes a HTTP POST request to the Web Service using a library like ASIHttpRequest library. (Note, for the backend, I wrote my web service using Symfony web framework)

2) The app sends back the JSON response.

e.g.

{
data
{
name: bob
age: 20
}
}

3) Parse the JSON using a JSON parser like JSONKit or the one provided by ASIHttpRequest and convert the JSON server response into a NSDictionary.

NSDictionary *data = [[request responseString] objectFromJSONString];

4) Now whether to store the data on the app or not depends on the nature of the app. If the app is to do searches for local restaurants, then you probably don’t want to keep a local copy of the returned result, since the nature of the app is to search for restaurants.

However, if you got like a login system that downloads user’s home work from their account, then you would likely store these data on the device locally.

This is where Core Data comes in, you build your model that replicates the server model and you do a simple 1 to 1 mapping between server and client models.

Hope that helps.

👤Zhang

2👍

Check out Rest kit

RestKit is an Objective-C framework for iOS that aims to make
interacting with RESTful web services simple, fast and fun. It
combines a clean, simple HTTP request/response API with a powerful
object mapping system that reduces the amount of code you need to
write to get stuff done.

It also supports persisting remotely loaded objects directly back into a local store

👤Venu

2👍

The Parse.com api is RESTful, and takes care of a kajillion hours of boilerplate code construction for a database. I don’t work for them, but I do like the service.

👤NSTJ

1👍

For #1, helios.io does the trick. From the docs at github,

In order to keep your data model and REST webservices in sync, you can link it to your helios application:

$ helios link path/to/DataModel.xcdatamodel

This creates a hard link between the data model file in your Xcode and Helios projects—any changes made to either file will affect both. The next time you start the server, Helios will automatically migrate the database to create tables and insert columns to accomodate any new entities or attribute

Leave a comment