You have a perfect example of web2py vs py4web.

Almost everything in your code works in both web2py and py4web but you 
action is a mix of both and works in neither.

@action('rest', method='GET') # this is py4web syntax only defined the 
def api():
    return RestAPI(db, policy)(request.method, request.args(0), 
request.args(1), request.get_vars, request.post_vars) # this is web2py 
syntax

In py4web there is no request.args, request.get_vars and request.post_vars 
and you have to use the bottle syntax:

@action('rest/<tablename>')
@action('rest/<tablename>/<id>') 
def api(tablename, id=None):
    return RestAPI(db, policy)(request.method, tablename, id, 
request.query, request.json)

This will expose /{appname}/rest/{tablename} and 
/{appname}/rest/{tablename}/{id}



On Friday, 26 July 2019 02:49:28 UTC-7, Kevin Keller wrote:
>
> Hello, 
>
> this is in my controller: 
>
> from pydal.restapi import RestAPI, Policy
>
> policy = Policy()
> policy.set('superhero', 'GET', authorize=True, allowed_patterns=['*'])
> policy.set('*', 'GET', authorize=True, allowed_patterns=['*'])
> policy.set('*', 'PUT', authorize=False)
> policy.set('*', 'POST', authorize=False)
> policy.set('*', 'DELETE', authorize=False)
>
> @action('rest', method='GET')
> def api():
>     return RestAPI(db, policy)(request.method, request.args(0), 
> request.args(1),
>                              request.get_vars, request.post_vars)
>
>
> and this in my models.py. 
>
> db.define_table(
>     'person',
>     Field('name'),
>     Field('job'))
>
> db.define_table(
>     'superhero',
>     Field('name'),
>     Field('real_identity', 'reference person'))
>
> db.define_table(
>     'superpower',
>     Field('description'))
>
> db.define_table(
>     'tag',
>     Field('superhero', 'reference superhero'),
>     Field('superpower', 'reference superpower'),
>     Field('strength', 'integer'))
>
>
> But I get 404 no matter how I try to access... 
>
> /test/rest/api.json/superhero?name.eq=Superman
>
> Also had to change the import from the docs from dbapi to restapi.. 
>
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/bd08e485-2215-4243-8249-dbd4b3a63362%40googlegroups.com.

Reply via email to