Changes between Version 1 and Version 2 of DeveloperGuidelines/WebServices


Ignore:
Timestamp:
01/02/09 07:00:34 (13 years ago)
Author:
Fran Boon
Comment:

Update for RESTlike controller

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines/WebServices

    v1 v2  
    33== Web Services ==
    44
    5 We want to be able to access data from the database exported as JSON for easy use within Javascript clients.[[BR]]
    6 This is very easy within Web2Py since 1.55:
     5We want to be able to access data from the database exported as JSON for easy use within Javascript clients.
     6
     7This can be done by simply calling the RESTlike controller with the var {{{?format=json}}}:
    78{{{
    8 # Designed to be called via AJAX to be processed within JS client
    9 def display_feature_group_features_json():
    10     list=db(db.gis_feature_group.id==t2.id).select(db.gis_feature_group.features).json()
    11     response.view='list_plain.html'
    12     return dict(list=list)
     9/sahana/module/resource?format=json           # Lists all records of this resource
     10/sahana/module/resource/id?format=json        # List record with record.id==id
     11/sahana/module/resource/create?format=json    # ToDo
     12/sahana/module/resource/update/id?format=json # ToDo
     13}}}
     14
     15The underlying functions are very easy within Web2Py since 1.55:
     16{{{
     17def display_json():
     18    "Designed to be called via AJAX to be processed within JS client."
     19    list=db(db.table.id==t2.id).select(db.table.ALL).json()
     20    response.view='plain.html'
     21    return dict(item=list)
    1322}}}
    1423