JAGQL - 为什么 post 调用需要 ID?
JAGQL - Why do I need an id for a post call?
我正在使用 JAGQL 构建一个 JSON API 兼容的 express 服务器。我背后的数据库是 MongoDB (jsonapi-store-mongodb)。我也在这里发布了我的问题:https://github.com/holidayextras/jsonapi-store-mongodb/issues/59
根据 JAGQL 文档,https://jagql.github.io/pages/project_setup/resources.html#generateid、
有人告诉我
generateId
By default, the server autogenerates a UUID for resources which are created without specifying an ID. To disable this behavior (for example, if the database generates an ID by auto-incrementing), set generateId to false. If the resource's ID is not a UUID, it is also necessary to specify an id attribute with the correct type. See /examples/resorces/autoincrement.js for an example of such a resource.
但是当我向我的资源之一发送 POST 请求时,我得到了这个:
"jsonapi": {
"version": "1.0"
},
"meta": {},
"links": {
"self": "/myresource"
},
"errors": [
{
"status": "403",
"code": "EFORBIDDEN",
"title": "Param validation failed",
"detail": [
{
"message": "\"id\" is required",
"path": [
"id"
],
"type": "any.required",
"context": {
"key": "id",
"label": "id"
}
}
]
}
]
我错过了什么?
详情请看这里:https://github.com/jagql/framework/issues/106
在您的资源定义中,您要添加 primaryKey: 'uuid'
:
{
resource: 'things',
handlers,
primaryKey: 'uuid',
attributes: {
...
}
}
我正在使用 JAGQL 构建一个 JSON API 兼容的 express 服务器。我背后的数据库是 MongoDB (jsonapi-store-mongodb)。我也在这里发布了我的问题:https://github.com/holidayextras/jsonapi-store-mongodb/issues/59
根据 JAGQL 文档,https://jagql.github.io/pages/project_setup/resources.html#generateid、
有人告诉我
generateId
By default, the server autogenerates a UUID for resources which are created without specifying an ID. To disable this behavior (for example, if the database generates an ID by auto-incrementing), set generateId to false. If the resource's ID is not a UUID, it is also necessary to specify an id attribute with the correct type. See /examples/resorces/autoincrement.js for an example of such a resource.
但是当我向我的资源之一发送 POST 请求时,我得到了这个:
"jsonapi": {
"version": "1.0"
},
"meta": {},
"links": {
"self": "/myresource"
},
"errors": [
{
"status": "403",
"code": "EFORBIDDEN",
"title": "Param validation failed",
"detail": [
{
"message": "\"id\" is required",
"path": [
"id"
],
"type": "any.required",
"context": {
"key": "id",
"label": "id"
}
}
]
}
]
我错过了什么?
详情请看这里:https://github.com/jagql/framework/issues/106
在您的资源定义中,您要添加 primaryKey: 'uuid'
:
{
resource: 'things',
handlers,
primaryKey: 'uuid',
attributes: {
...
}
}