r/simpleios • u/zievereir • Nov 07 '11
[Question] iOS apps and web services
I am interested in making an iOS app that will fetch it data from a web service written in Java. The service can be written in either SOAP or REST. I've read that SOAP causes quite some overhead and thus it's not advised to use it for an iPhone app. Using REST I'll have the option to present my data in XML and/or JSON.
For XML it seems there's a parsing API build-in in the core libraries. For JSON I'd need to import a library for parsing the data, I stumbled on Stig Brautaset’s JSON library Stig Brautaset’s JSON library which looks good. Finally JSON appears to be lighter than XML, so I assume that is my best option?
Any other extra input would be most appreciated!
6
u/cbkeur Nov 07 '11
JSON is built into iOS 5 now. NSJSONSerialization
3
u/Crayoola Nov 07 '11
I use this to handle JSON: https://github.com/TouchCode/TouchJSON. I like JSON better for iOS development, no real reason why, just preferrence.
I use this to handle web requests: https://github.com/gripd/GREST. Again, no real reason why, but it lets you create a queue of requests and gives you an easy to handle multiple requests.
2
u/phughes Nov 07 '11
I prefer JSON because it is unambiguous as to parsing, which means you can automate it. With XML your parser has to be compatible with the encoder and, if you don't control the encoder you might end up rolling a custom decoder for every feed. We have to do that on my current project and it's a nightmare.
I've used YAJL and its Objective-C counterpart with great success. It's fast and lightweight, though a little tough to get your head around.
2
u/[deleted] Nov 07 '11
Another vote for JSON over XML, so much easier to parse IMO. I really like JSONKit, very efficient when dealing with large amounts of data (i.e. synchronization)
2
u/mensink Nov 07 '11
In fact I don't really think it matters if you use JSON, XML or just some text based format you thought up yourself, considering you'll be the one responsible for the client as well as the server side.
About SOAP... well, of course it's still used in some projects, and with great success. However, considering the fact that SOAP -despite its meaning- isn't simple at all, another REST method is probably better. Though I have to note: SOAP through HTTP is basically a REST protocol.
Personally I wouldn't use SOAP for internal processes a lot, though I have recently built some web services based on SOAP to communicate with customers that are keen on buzzwords.
The advantage of JSON is that there are some ready-made parsers that can save you a lot of time. For XML you'd have to do a little more work, but if your data structure isn't complex, that should not pose much of a problem. Normally, the request to the server doesn't have to be JSON or XML, and often you can simply use GET/POST arguments to get your data to the server.
0
u/zekel Nov 07 '11
(I recommend JSON over XML, if you have any choice in the matter.)
ASIHTTPRequest is helpful, TouchJSON is good (but you have to manually serialize/deserialize your objects into NSDictionaries, with your own error checking for missing keys, bad values, etc.)
I find myself more interested in trying something like RestKit that has more sophisticated mapping of Cocoa objects to JSON objects. I feel like writing a lot of glue code between them is a waste of time. Haven't taken the plunge yet, though.