milepile
milepile

Reputation: 141

PHP RESTful Web Service for an iPhone

I'm developing an iPhone APP and need to implement also an Web Service. First of all I'm not a Developer and never made something big in PHP, Objective-C, xCode. My PHP knowledge isn't also good. But let's start with my Environment.

iPhone APP (xCode 4.2, iOS5), PHP Web Service, MySQL DB

I was researching the WEB and most People tend more to REST than SOAP. I think i see also the advantages of REST (using of simple HTTP Verbs (get, post, delete etc...), but that's not the main point here...

I think I understand the main goal of the REST Architecture and tried to make a little concept with an URI and Verb Mapping. Here just a simple example of the mapping:

/location/{location_id}/product
/location/{location_id}/product/{product_id}

Both are GET operations who should get me ether a single product or all products of a location.

How would a simple PHP REST Web Server look like with these functions?

Another part should implement a User Authentication from the iPhone. Somehow i need to store the user session, right now I don't have any idea how to make that. The goald is that if only a user is logged in, he could review the product.

Now I've researched also the Web but couldn't find an easy step-by-step Tutorial. Do you know any good Tutorials which will help me achieve my goal? :)

A lot of people prefer using PHP Frameworks like ZEND. This seems very interesting, but it seems like a big package with a lot of modules. Does someone know exactly which Modules are needed to get my Web Service working?

Upvotes: 4

Views: 2943

Answers (2)

Dizzler
Dizzler

Reputation: 45

If you want to build this the custom way it's actually very easy to do if you want to return information in the JSON format especially for php5 which is generally well supported amongst hosts these days.

Essentially the steps are like this:

  • Pass in product id via url and retrieve using GET i.e. service.php?product_id=10
  • Query database and return data for product id that was passed in
  • Store returned data in an array
  • Set header content-type to application/json
  • json_encode the result (json_encode)

That way when you call that url in a browser you will get a nice JSON formatted array result in a key:value pair manner. And as of iOS5 json parser comes with the framework (for earlier versions SBJson is a good framework to use (SB JSON))

Upvotes: 0

Josh
Josh

Reputation: 3475

This is quite a good tutorial, it uses the codeigniter framework which makes the learning curve a bit steeper but makes it a lot more powerful in the long run.

http://net.tutsplus.com/tutorials/php/working-with-restful-services-in-codeigniter-2/

Upvotes: 2

Related Questions