views:

152

answers:

2

I'm sending a lot of JSON requests from a native iPad application to my Django web server. How do I translate forms I use on my website to handle an iPad web service?

Am I trying to solve the wrong problem, should a web service used from native iPad applications be redesigned to use REST-ful requests?

+1  A: 

Well, first of all, this question should really be:

"How do I write a RESTful API using Django and JSON?"

iPads are just like any other web browser (client), and they can use javascript, JSON, etc.

Here's a high level description of what you need to do:

  1. Write a Django view and map it to a URL, eg: /api/some_action/
  2. Write out the body of your view, have it perform whatever action you need on the server.
  3. Write the HTML/javascript code which is displayed on a user's iPad, so that when iPad users visit a part of your website (let's say /home/) they'll make a JSON request to your server which talks to the API (eg, sends some JSON to /api/some_action/)

Once your Javascript code sends JSON to the API view, your view should process that JSON, and perform whatever actions you want.

This is the way most web-services are developed.

Hope that helps!

b14ck
I'm not using HTML/Javascript on the iPad, I'm writing a native iPad application.
MikeN
@MikeN Replace "HTML/javascript" in point 3 with "native iPad application". The principle is the same and the point of an API is that it doesn't care where from or how the request came in.
Colonel Sponsz
@MikeN, Colonel Sponsz basically nailed exactly what I mean on the head. Regardless of whether or not you are using HTML/Javascript, you can still generate HTTP requests from your iPad application.I'm not an iPad developer, so I don't know the Apple APIs, but I guarantee you there is something like 'curl' which can send HTTP requests to a web server easily.
b14ck
A: 

Can the iPad (or iPhone/iPod) browser send PUT/DELETE commands? For me that's the biggest trouble when trying to do REST-like apps in JavaScript.

In the end, what i tend to do is to have small Django views (mostly using the create_update generic views) to handle the HTML/form/model integration; and in JS, i use jQuery's $('#dialog').dialog().load('dialogurl') to open a dialog and load it with the form generated by Django. Be sure to either manage the submit() yourself.

I'd prefer a lot to just write a REST server (probably using Django-Piston) and a full client app on the browser; but so far i haven't found a nice enough JS framework. (pyjamas or qooxdoo sound great, but fall 'just a little short')

Javier
Trying to use native iPad applications, not a web browser on the iPad.
MikeN
@MikeN: then, yes, go full REST!
Javier