Changes between Version 14 and Version 15 of DeveloperGuidelines/WebServices


Ignore:
Timestamp:
08/12/09 16:27:50 (16 years ago)
Author:
Fran Boon
Comment:

Most webservices clients are stateless. Reorganise layout

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/WebServices

    v14 v15  
    11== Web Services ==
    22
    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:
    244  * http://web2py.com/examples/default/tools#services
    255  * http://groups.google.com/group/web2py/browse_thread/thread/53086d5f89ac3ae2
     
    299{{{
    3010from gluon.tools import Service
    31 service=Service(globals())
     11service = Service(globals())
    3212}}}
    3313Controller:
     
    4626 * http://groups.google.co.uk/group/web2py/browse_thread/thread/98258d69b6a6f927
    4727
     28Note 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----
     33We 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
    4841----
    4942Another approach (using JSONRPC e.g. with [http://pyjs.org Pyjamas]):
    50 
    5143 * http://mdp.cti.depaul.edu/AlterEgo/default/show/203
    5244 * http://groups.google.com/group/web2py/browse_thread/thread/9bb107c2fbd1a34b