Python 前夕对资源和项目端点的不同预测

Different Projections on Resource and Item Endpoints in Python Eve

我是 RESTful API 的新手。所以请原谅我的无知

假设我有一个 MongoDB 集合 foobars,其中包含一些文档。结构如下: [{'_id': 1, 'foo': 1, 'bar': 1}, {'_id': 2, 'foo': 2, 'bar': 2},...]

我想设置两个端点:

我在域中设置了投影

DOMIAN = {
    'foobars': {
        'schema': {...},
        'datasource': {
            'projection': {'_id': 1}
        }
    }
}

这在资源级别上按预期工作。但是在项目级别它仍然只有 return 投影字段。

我应该如何正确定义投影?我应该为同一资源设置多个端点吗?谢谢!

我想出了一个解决方法。也许不是 RESTful 方式,因为它看起来多余。

DOMAIN = {
    'foobar_list': {
        'schema': {...},
        'datasource': {'source': 'foobars'},
        'projection': {'_id': 1}
    },
    'foobar_item': {
        'schema': {...},
        'datasource': {'source': 'foobars'},

        # Disable resource level endpoint
        'resource_methods': [],
    },
}