== Web Services == Our main solution for Web Services is to use [wiki:S3XRC S3XRC] for Import/Export of XML &/or JSON. ---- {{{gluon/tools.py}}} supports easy exposing of functions to XMLRPC or JSONRPC: * http://web2py.com/examples/default/tools#services * http://groups.google.com/group/web2py/browse_thread/thread/53086d5f89ac3ae2 (originally in T3: http://groups.google.com/group/web2py/browse_thread/thread/9ec8b06b158adb75): Model: {{{ from gluon.tools import Service service = Service(globals()) }}} Controller: {{{ @service.jsonrpc @service.xmlrpc @service.amfrpc def organisation(): "RESTlike CRUD controller" return shn_rest_controller(module, 'organisation') }}} Can test authentication/REST using wget/curl: * http://groups.google.com/group/web2py/msg/dde8335c4ec26b99 * Rest-UI client: http://code.google.com/p/rest-client/ Token-based authentication: * http://groups.google.co.uk/group/web2py/browse_thread/thread/98258d69b6a6f927 Note that most web-services clients don't support cookies & hence are stateless (no sessions support): * http://groups.google.com/group/web2py/browse_thread/thread/6538ae13cb8f28d3 * use {{{session.forget()}}} inside controllers expecting such clients * XML-RPC client which does support Cookies: http://code.activestate.com/recipes/501148/ ---- We can access data from the database exported as JSON (for easy use within Javascript clients) by simply calling the [https://trac.sahana3.org/wiki/BluePrintREST RESTlike controller] with the var {{{?format=json}}}: {{{ /sahana/module/resource?format=json # Lists all records of this resource /sahana/module/resource/id?format=json # Display record with record.id==id /sahana/module/resource/create?format=json # ToDo /sahana/module/resource/update/id?format=json # ToDo }}} ---- Another approach (using JSONRPC e.g. with [http://pyjs.org Pyjamas]): * http://mdp.cti.depaul.edu/AlterEgo/default/show/203 * http://groups.google.com/group/web2py/browse_thread/thread/9bb107c2fbd1a34b ---- Twitter feeds as JSON: * http://groups.google.com/group/web2py/browse_thread/thread/bb9b5ddca40d0c87 ---- DeveloperGuidelines