I am working on a REST interface for ORM objects for a Kohana website. I’ve got two controllers so far:
Controller_Api_Product
URL: api.example.com/product/<product_id>
Controller_Api_Category
URL: api.example.com/category/<category_id>
Each of these accepts the following methods and updates the record succesfully.
- POST: Create
- GET: Read
- PUT: Update
- DELETE: Delete
I’d like to create a some way of handling ORM’s has_many properties. For example I’d like to be able link a product and a category together. I have this relationship stored in a separate table (products_categories). I don’t have an ORM model for that table (as I don’t store any extra relationship data).
What would be the best way to manage it? Should I create an ORM model for the table and it’s own controller?
Controller_Api_Product_Category
URL: api.example/product_category/<product_category_id>
Should I use a different HTTP method (eg. LINK)?
Controller_Api_Product_Category called with method LINK
URL: api.example/product/<product_id>
Should I have some other completely different controller which isn’t bound to a specific model?
Controller_Api_Link
URL: api.example.com/link/product/<product_id>/category/<category_id>
Having a separate link controller can obviously be used for any objects. I’m just a bit stumped on how to extend my REST API beyond the normal CRUD actions.
I’d say if you already have a link stored in table, you should use it like any other object?
and perform CRUD operations on the link itself.