PHP RESTful Web Service for iPhone

I am developing an iPhone APP and must also implement a web service. First of all, I am not a developer and have never done something big in PHP, Objective-C, xCode. My PHP knowledge is not good either. But let it begin with my environment.

iPhone APP (xCode 4.2, iOS5), PHP web service, MySQL DB

I studied WEB and most people prefer REST over SOAP. I think I also see the benefits of REST (using simple HTTP verbs (get, post, delete, etc.), but this is not the point here ...

I think I understand the main purpose of the REST architecture and am trying to make a small concept with a URI and display of verbs. Here is just a simple display example:

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

Both are GET operations that should receive me a broadcast of one product or all products of a location.

What would a simple PHP REST web server look like with these features?

The other part is to implement user authentication with the iPhone. Somehow I need to save a user session, right now I do not know how to do it. The goal is that, as soon as the user is logged in, he can view the product.

Now I also explored the Web, but could not find an easy walkthrough. Do you know good tutorials to help me achieve my goal? :)

Many people prefer to use the PHP Framework, such as ZEND. It seems very interesting, but it looks like a big package with a lot of modules. Does anyone know which modules are needed for my web service to work?

+4
source share
2 answers

This is a pretty good tutorial, it uses a codeigniter structure that makes the learning curve a little steeper, but makes it much more powerful in the long run.

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

+2
source

If you want to create this custom method, it is actually very easy to do if you want to return information in JSON format, especially for php5, which today is well supported among hosts.

Essentially the steps are:

  • Pass product id to url and get using GET ie service.php? product_id = 10
  • Request a database and return data for the product identifier that was transferred to
  • Store returned data in an array
  • Set header content type to application / json
  • json_encode result ( json_encode )

Thus, when you call this URL in a browser, you will get a great formatted array of JSON array as a key: value pair. And with iOS5, json parser comes with a framework (for earlier versions of SBJson, a good framework to use ( SB JSON ))

0
source

Source: https://habr.com/ru/post/1398789/


All Articles