web2py RESTful service - POST and PUT

50 views
Skip to first unread message

Kristina Nikolic

unread,
Aug 25, 2014, 2:44:35 PM8/25/14
to web...@googlegroups.com
Hi!

I'm making Android application which connects to my simple web2py application. I'm successful at making GET, POST, PUT and DELETE calls for table that I have made. However, when I try to make POST or PUT call for auth_user table, nothing happens.

This is my code for RESTful (I found it here: http://www.web2pyslices.com/slice/show/1533/restful-api-with-web2py)  :

@request.restful()
def api():
    response.view = 'generic.'+request.extension
    def GET(*args,**vars):
        patterns = [ 
                    "/mytable[mytable]",
                    "/mytable[mytable]/{mytable.id}",
                    "/user[auth_user]/{auth_user.id}",
                    "/user[auth_user]",
                    ]
        parser = db.parse_as_rest(patterns,args,vars)
        if parser.status == 200:
            return dict(content=parser.response)
        else:
            raise HTTP(parser.status,parser.error)
    def POST(table_name,**vars):
        return db[table_name].validate_and_insert(**vars)
    def PUT(table_name,record_id,**vars):
        return db(db[table_name]._id==record_id).update(**vars)
    def DELETE(table_name,record_id):
        return db(db[table_name]._id==record_id).delete()
    return dict(GET=GET, POST=POST, PUT=PUT, DELETE=DELETE)

Can somebody tell me why is that happening? Is it possible that I cannot make POST  and PUT calls for auth_user table?
Reply all
Reply to author
Forward
0 new messages