python eve restful 规则

来源:互联网 发布:人工智能李开复读后感 编辑:程序博客网 时间:2024/04/30 10:31

1、?max_results=1&page=1 页数和当页最大数值

2、设置媒体文件返回信息

RETURN_MEDIA_AS_BASE64_STRING=False,

RETURN_MEDIA_AS_URL=True,

EXTENDED_MEDIA_INFO=['content_type', 'name', 'length'],

MEDIA_ENDPOINT='pics'

3、?projection={"image": 0/1}在url端时是否显示该字段

在资源端时,直接控制该字段是否显示

people = {
    'datasource': {
        'projection': {'image': 0}
    },
    ...
} 
4、bills = {
    'datasource': {
        'source': 'bills',资源名
        'filter': {'field1': 'value1', 'field2': 'value2'}mongodb数据库查询集合
    }
}
 
5、
current_app.auth.get_request_auth_value() 获取当前用户
self.set_request_auth_value(user['_id'])保存当前用户id

 

6、

GET/parents?max_results=10&embedded={"children":1}&projection={"children.a":1,"children.c":1}

这个接口可能是选择嵌入文档的显示字段

 

7、如果想对某个资源进行不同的认证,可以用DOMAIN={

    'people':{

        'authentication':MySuperCoolAuth,#认证的方法

        ...

        },.#可以覆盖全局认证

    }

8、如果想让某个api端点可以让非认证用户访问,比如只读,可以用DOMAIN={

    'people':{

        'public_methods':['GET'],

        'public_item_methods':['GET'],

        },

    }

这样没有认证的用户可以用get方法读取这个资源,也可以全局设置。

9、flask 请求钩子

before_first_request:在处理第一个请求之前运行

before_request:在每次请求之前运行

after_request:如果没有未处理的异常抛出,在每次请求之后运行

teardown_request:即使有未处理的异常抛出,也在每次请求之后运行


 

原创粉丝点击