You raise some good issues. T2 itself does not follow rest because t2 does not expose any action. But by figuring out which record you want from the path_info it allows you to code actions that follow (at least partially) rest.
Massimo On Oct 22, 5:04 am, billf <[EMAIL PROTECTED]> wrote: > Having done some speed reading on REST, there seem to be a few primary > features: > - it is about identifying resources > - a uri identifies a resource type, e.g. "orders" (99.9% of examples > use the plural of the resource type), likehttp://example.com/orders > - a uri may optionally identify a specific resource > likehttp://example.com/orders/25 > - uri may specify resources such as an html form > likehttp://example.com/findOrderForm > - there doesn't seem to be one agreed method for combining > identification of resource with the action to be taken, for example > > - doeshttp://example.com/ordersreturn a list of all orders or an > empty order form > to create a new order > - doeshttp://example.com/orders/1return a read-only version of an > order or a > populated form to be used for updating the resource > > However, when coded as per the T2 manual examples, it seems web2py/T2 > considers > the controller/action as the resource(?) > > For example, given a controller called default.py with an action > "orders" thenhttp://example.com/default/orders/1 > can be used to return a form containing order where id=1 using > t2.update(db.order) > but throws an error when invoked withhttp://example.com/default/orders > > One can implement a version of the REST approach by adding code to the > hypothetical default.py/orders action (checking the presence of > request/ > args and using t2.create or t2.update accordingly) but if T2 is > intending to be RESTful shouldn't that be built in? > > In fact, the T2 manual examples (pg. 13) are really CRUD (create > included in index(), > display() and update() actions). > > So does T2 follow REST? or am I missing the point (not for the first > time)? > > On Oct 21, 10:31 pm, billf <[EMAIL PROTECTED]> wrote: > > > REST - tbh never heard of it before but it looks interesting - thank > > you. > > > On Oct 21, 8:37 pm, mdipierro <[EMAIL PROTECTED]> wrote: > > > > because I want T2 to follow REST (update/1). Form submission also POST > > > (id=1&name=massimo&etc) > > > > On Oct 21, 1:44 pm, billf <[EMAIL PROTECTED]> wrote: > > > > > My understanding of the mechanism and yours seem exactly the same. My > > > > question was WHY you designed the t2 update controller to expect a url > > > > like > > > > .../update/1 as opposed to .../update?id=1? > > > > > On Oct 21, 5:07 pm, mdipierro <[EMAIL PROTECTED]> wrote: > > > > > > Unless I misunderstand the question and I messed up this is how I > > > > > think it works. > > > > > > 1) All t2 controllers that need a record id (update, delete, etc.) > > > > > expect a url like ..../update/1 where args[-1] is the id of the > > > > > record. > > > > > There is no exception to this rule. > > > > > > 2) When you submit a form (create, update, etc) the variables are > > > > > passed in the form. In the case of update the variables contain the > > > > > hidden 'id'. This mechanism is inherited from SQLFORM. This may seem > > > > > redundant but it is not. In fact in t2 you can change 1) and set your > > > > > own t2.id so that you can create an update form based on a different > > > > > criteria. In this case there is no id in the url but you still want to > > > > > make sure SQLFORM knows what id the visitors thinks he/she is editing. > > > > > > Massimo > > > > > > On Oct 21, 9:46 am, billf <[EMAIL PROTECTED]> wrote: > > > > > > > When using the t2.update() method it seems mandatory that the id is > > > > > > passed in initially as an argument (i.e. part of the path) but on > > > > > > return from the update form it is expected as a parameter (i.e. > > > > > > ?id=1) > > > > > > from a hidden input tag? > > > > > > > This seems to be the only example where an argument is expected. > > > > > > All > > > > > > other form fields including stamp columns and formkey are passed as > > > > > > parameters. I just wondered "why the exception"? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---