搜索文档是否存在于 JSON API 中,而不是通过主标识符
Search whether a document exists in a JSON API, not by primary identifier
我正在构建 JSON API 并拥有 user
资源。 user
将 id
作为其主要标识符和一些其他字段:facebook_id
、linkedin_id
等等。
我需要检查某个 user
是否存在,只能通过其他字段之一(例如:facebook_id
)。我无法使用 /users/<id>
并检查它是否 return 是 404
,因为我没有主标识符。
我考虑过使用 /users/exists?<field>=<value>
,但我不确定这是否是 JSON API 的正确方法。
我的问题是,我应该创建什么端点,它应该 return 什么代码以防文档存在或不存在,以及主体是什么?
您可以使用 facebook id 作为查询字符串中的参数,例如:
GET /users?facebookId=12345
如果http状态码响应为200则用户确实存在,内容为用户资源,例如:
/users?facebookId={fb_id}:
get:
summary: ...
description: ...
parameters:
- name: fb_id
in: path
required: true
type: integer
responses:
"200":
description: ...
schema:
$ref: '#/definitions/userResource'
我正在构建 JSON API 并拥有 user
资源。 user
将 id
作为其主要标识符和一些其他字段:facebook_id
、linkedin_id
等等。
我需要检查某个 user
是否存在,只能通过其他字段之一(例如:facebook_id
)。我无法使用 /users/<id>
并检查它是否 return 是 404
,因为我没有主标识符。
我考虑过使用 /users/exists?<field>=<value>
,但我不确定这是否是 JSON API 的正确方法。
我的问题是,我应该创建什么端点,它应该 return 什么代码以防文档存在或不存在,以及主体是什么?
您可以使用 facebook id 作为查询字符串中的参数,例如:
GET /users?facebookId=12345
如果http状态码响应为200则用户确实存在,内容为用户资源,例如:
/users?facebookId={fb_id}:
get:
summary: ...
description: ...
parameters:
- name: fb_id
in: path
required: true
type: integer
responses:
"200":
description: ...
schema:
$ref: '#/definitions/userResource'