0

I'm following these tutorials thoroughly and must say they're great tutorials!

http://www.techchorus.net/create-restful-applications-using-zend-framework

I'm just confused about the whole concept of Zend_Rest abstract methods. In the examples, you only see

index POST GET PUT DELETE

While these functions make sense, I'm trying to figure out if the whole architecture is only limited to those abstract methods. I'm thinking about a use case where a consumer wants to use the API to update specific fields in lets say the user table, or another case where the consumer wants to update activity table. The business logic of these two tables are covered in one RESTful api controller. I would tackle this problem by creating specific update/post method for each table, and have function parameters to define which fields are being updated. Would this kind of implementation conform with REST and if so how do you go beyond POST,GET, PUT, DELETE methods?

shiva8
  • 2,142
  • 2
  • 19
  • 24

1 Answers1

0

REST architecture does support hierarchical relationships for resources, and your resources are not bound with your database in any way. Your “User” resource might have a subresource “Credentials” that maps to username and password fields in your users table, so you could do a PUT request on “domain.com/users/{userId}/credentials”. You will implement this by creating a controller, say UserCredentials, and the update logic would be in the putAction.

You will have to modify the routing for this to work in Zend though. See How to set up Hierarchical Zend Rest Routes?

Community
  • 1
  • 1
ksiimson
  • 593
  • 3
  • 8
  • Seems like a very stringent solution, so every time the database scheme changes I have to update all these custom routes also. I just thought of another simpler solution, what if I define the table and fields to put as get parameters and just use this function func_get_args() to get all the parameters and sort it out by key=>value? – shiva8 Jul 11 '12 at 23:36
  • Encapsulate database structure to minimize changes in resources and URLs. Design your resources so they don't reflect your database structure. Keep in mind a PUT request can include multiple key-value pairs. – ksiimson Jul 11 '12 at 23:40