Hi,

I'm trying to ajust the output of the REST services.

Here is my code:

@request.restful()
def api():
    response.view = 'generic.json'
    def GET(tablename,**vars): # GET VALUES
        if not tablename=='test': raise HTTP(400)
        if request.vars.search == None:
            return dict(test= db(db.test).select())
        else : 
            return dict(test = db(db.test.testname.contains(vars['search'
])).select())
    def DELETE(tablename,id):
        if not tablename=='test': raise HTTP(400)
        return db(db.test.id == id).delete()
    def PUT(tablename,record_id,**vars):
        if not tablename=='test': raise HTTP(400)
        if record_id=='': raise HTTP(400)
        return db(db.test._id==record_id).update(**vars)
    def POST(tablename,**vars):
        if not tablename=='test': raise HTTP(400)
        return db.test.validate_and_insert(**vars)
    return locals()

For example, the GET method gives me this output:
{"test": [{"testname": "test18", "id": 4, "testvalue": "119"}, {"testname": 
"test18", "id": 10, "testvalue": "119"}, {"testname": "test19", "id": 11, 
"testvalue": "edt125"}, {"testname": "lmklm", "id": 19, "testvalue": "opopo"
}, {"testname": "test19", "id": 20, "testvalue": "edt125"}, {"testname": 
"lmkhjkhj", "id": 21, "testvalue": "lmmmjkhjk"}, {"testname": "jj", "id": 22
, "testvalue": "lmmmjkhjkghgh"}, {"testname": "jjhhh", "id": 23, "testvalue"
: "hjhgj"}, {"testname": "jjhhhjhgjh", "id": 24, "testvalue": "hjhgjhh"}]} 

*How coud I get this output:*

{*"Result" : "OK"*, "test": [{"testname": "test18", "id": 4, "testvalue": 
"119"}, {"testname": "test18", "id": 10, "testvalue": "119"}, {"testname": 
"test19", "id": 11, "testvalue": "edt125"}, {"testname": "lmklm", "id": 19, 
"testvalue": "opopo"}, {"testname": "test19", "id": 20, "testvalue": 
"edt125"}, {"testname": "lmkhjkhj", "id": 21, "testvalue": "lmmmjkhjk"}, {
"testname": "jj", "id": 22, "testvalue": "lmmmjkhjkghgh"}, {"testname": 
"jjhhh", "id": 23, "testvalue": "hjhgj"}, {"testname": "jjhhhjhgjh", "id": 
24, "testvalue": "hjhgjhh"}]} 

Or, another issue,* the output without the "test":* 
{"testname": "test18", "id": 4, "testvalue": "119"}, {"testname": "test18", 
"id": 10, "testvalue": "119"}, {"testname": "test19", "id": 11, "testvalue": 
"edt125"}, {"testname": "lmklm", "id": 19, "testvalue": "opopo"}, {
"testname": "test19", "id": 20, "testvalue": "edt125"}, {"testname": 
"lmkhjkhj", "id": 21, "testvalue": "lmmmjkhjk"}, {"testname": "jj", "id": 22
, "testvalue": "lmmmjkhjkghgh"}, {"testname": "jjhhh", "id": 23, "testvalue"
: "hjhgj"}, {"testname": "jjhhhjhgjh", "id": 24, "testvalue": "hjhgjhh"} 

I tried different methods by processing the output, which is fine, but I 
would prefer to do it from the REST service.

Mike

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to