开发者

How to create my own Web API / Web Service

开发者 https://www.devze.com 2023-02-13 08:31 出处:网络
I have been developing iOS apps for 开发者_开发知识库a while but they all deal with information that is on the device.

I have been developing iOS apps for 开发者_开发知识库a while but they all deal with information that is on the device.

I want to expand my knowledge and the appeal of my apps.

What I need is a good tutorial on how to create my own online SQL database and an API to acces all the information on it.

I have used several APIs (Twitter, Facebook, Google, etc.) so on the iOS side I'm ready.

I would love to implement it using Google App Engine but If you know of beter ways to implement this I am more than glad to hear them; I've heard that Java, .net and Ruby are the best options.

I have found a lot of tutorials online but I know Stack Overflow users have knowledge of great resources that can help me, and other developers, to get up and running faster, easier and learning more.

I think the answers to this question can be a great resource to all developers interested on Wb APIs.

Thank you very much for your help.


IMHO, AppEngine is a great choice, since there is virtually no need to setup/manage it. Also it comes prepackaged with powerful services like datastore, taskqueue, user auth, messaging, etc.. The biggest advantage for me is the Datastore, which is schemaless, so you don't have to constantly update/manage the schema as your app progresses.

The downside is that it has somewhat different programming model so developers from servlet+SQL background tend to struggle with it at first. Since you are new to this it shouldn't be a problem.

All my advices below are Java, as this is what I know. Hopefully others will post answers that present other platforms/languages.

To get this running you will need to:

  1. Setup a web service. Go with REST as this is the most common and easy to setup/use. I tried all major Java REST frameworks and ended up with Resteasy, because it just works and has IMHO the best documentation.

  2. Understand how GAE Datastore works. There are a few APIs to use the Datastore:

    a. Low-level is cumbersome as you need to use it's model classes (Entity) so you'll do a lot of copying between your objects and Entity objects returned by this API.

    b. JDO/JPA are java ORM standards, but they were created for SQL databases and are really shoehorned onto Datastore. I'd advise against using them, because they are just an additional layer on top of low-level and also just try to fool developers that Datastore is a SQL database.

    c. Objectify. This is a 3rd party OSS library, but the author is AFAIK supported by Google. It's a layer on top of low-level, but in a really natural way, so not to obscure Datastore features. I recommend using it.

  3. Authentication. You will want authentication. GAE supports OpenID/OAuth out of the box (just tick federated login option in command panel). Now the tricky part is to get this working with iPhone and other devices:

    a. Require user to enter Google credentials into your iPhone app. Some users are reluctant to do this (me for instance). In this case use iPhone OAuth client.

    b. Open an OpenID login web page in embedded browser: Authenticating with Stack Overflow programmatically


I've done several app back-ends in "raw" PHP/MySQL (no frameworks). The advantage to this approach is that it's really, really easy to do, and every single hosting company in existence supports both PHP and MySQL. If your back end is exclusively for an iphone, you can even return all data in plist-format xml that requires zero parsing and can instantly be converted into dictionaries/arrays in the iphone app.

Another advantage is that you can set up a test server on your dev system or home network and you can test the back-end locally via the iphone simulator and even your iphone device as long as you use IP addresses instead of names (and if you're a good sysadmin/network person, you could probably set it up to use your network names, too).

The disadvantage to raw PHP/MySQL is that you don't get the administrator interfaces for free for managing/editing data entities like with most of the frameworks like django. Another disadvantage is scaling to large volume of traffic -- but if you're using a reasonable hosting service, that may not be a problem.

There are tons of books and materials online for doing php/mysql web sites.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号