问题描述:

I'm developing a tool that will comprise a central website and a desktop application. I've only really done entirely online developent, or entirely offline/client-side development before and not really had to link the two. I could use some help in how to approach passing data to/from the online site & desktop app.

The desktop app needs to communicate & do some control of iTunes, so initially I'm building this in Cocoa on OSX & making use of the ScriptingBridge framework.

On the website side I'm thinking of using Ruby on Rails, with data stored in a mySQL database, as I'm fairly familiar & seems like a good match for the online job it has to do. (But open to other suggestions if there's a better approach!)

I'm struggling to find the best approach to easily transfer data between the Cocoa app & the online rails database - is there a simple way of having the Cocoa app access the online database directly, or is it typical to dump some XML onto the webserver and have the app read that?

网友答案:

Opening a RESTful API on your RoR system is as simple as you can get. Have your desktop app communicate with that API using JSON or XML.

Advantages to using JSON rather than XML: (1) extremely simple to manipulate in Rails (2) extremely simple to work with in Javascript, should the need arise to build a web client in addition to the desktop one.

It's a very bad idea to have the desktop app communicate directly with your remote database. Two main reasons:

  1. Security. Such a setup just begs to be hacked. Some databases are "built for the web" (CouchDB comes to mind) and would be alright here, but MySQL isn't.

  2. Flexibility. With desktop application in the field, making changes and distributing them to all clients is hard. Should the need arise to change your schema, the web application layer frequently allows you to keep the interface with the desktop clients stable.

相关阅读:
Top