| 3 | | We want to be able to access data from the database exported as JSON for easy use within Javascript clients. |
| 4 | | |
| 5 | | This can be done by simply calling the [https://trac.sahana3.org/wiki/BluePrintREST RESTlike controller] with the var {{{?format=json}}}: |
| 6 | | {{{ |
| 7 | | /sahana/module/resource?format=json # Lists all records of this resource |
| 8 | | /sahana/module/resource/id?format=json # Display record with record.id==id |
| 9 | | /sahana/module/resource/create?format=json # ToDo |
| 10 | | /sahana/module/resource/update/id?format=json # ToDo |
| 11 | | }}} |
| 12 | | |
| 13 | | The underlying output functions are very easy within Web2Py since 1.55: |
| 14 | | {{{ |
| 15 | | def display_json(): |
| 16 | | "Designed to be called via AJAX to be processed within JS client." |
| 17 | | list = db(db.table.id==t2.id).select(db.table.ALL).json() |
| 18 | | response.view = 'plain.html' |
| 19 | | return dict(item=list) |
| 20 | | }}} |
| 21 | | |
| 22 | | ---- |
| 23 | | {{{tools.py}}} now supports easy exposing of functions to XMLRPC or JSONRPC: |
| | 3 | {{{gluon/tools.py}}} supports easy exposing of functions to XMLRPC or JSONRPC: |
| | 28 | Note that mot web-services clients don't support cookies & hence are stateless (no sessions support): |
| | 29 | * http://groups.google.com/group/web2py/browse_thread/thread/6538ae13cb8f28d3 |
| | 30 | * XML-RPC client which does support Cookies: http://code.activestate.com/recipes/501148/ |
| | 31 | |
| | 32 | ---- |
| | 33 | 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}}}: |
| | 34 | {{{ |
| | 35 | /sahana/module/resource?format=json # Lists all records of this resource |
| | 36 | /sahana/module/resource/id?format=json # Display record with record.id==id |
| | 37 | /sahana/module/resource/create?format=json # ToDo |
| | 38 | /sahana/module/resource/update/id?format=json # ToDo |
| | 39 | }}} |
| | 40 | |