On Thursday, January 5, 2017 at 12:39:13 AM UTC-5, Brendan Barnwell wrote:
>
> It looks like I could use request.restful for that, but to be honest I 
> find that mechanism somewhat awkward.  Creating functions as local 
> variables and then returning locals() just seems gross to me.  :-)
>

Not sure why that is "gross," but you don't have to code it like that -- 
the decorated function simply has to return a dictionary whose keys are one 
or more of the HTTP verbs (GET, POST, etc.) and whose keys are the 
functions that should be called in response to those verbs. You can create 
that dictionary however you like and define the functions wherever you like.
 

> But from the other side of things, I guess the question is, if we can do 
> that, is there ever any reason to use the "service" mechanism at all?  Or 
> can request.restful do everything service can do, and more?
>

I suppose their use cases are overlapping. If @request.restful works for 
you in this case, then use it. The @service mechanism lets you easily 
expose functions for use in remote procedure calls, including via 
standardized RPC protocols. The @service decorators also automatically 
return the correct response format, whereas @request.restful requires the 
use of the generic views (disabled by default) to automatically generate 
different response formats (though it will automatically generate JSON if 
the request specifies "application/json").

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to