布尔端点的 RestAPI 命名约定



这是一个微不足道的问题,但我找不到答案。假设我有一个端点,它只是检查某个组中是否存在用户并返回一个布尔值。RestAPI 路径应该是什么样子的?

/api/user/{id}/exists/{group}

/api/user/{id}/in/{group}

/api/user/{id}/is_assigned/{group}

/api/user/{id}/exists_within/{group}

我觉得 API 路径名应该有机地阅读,但我也不喜欢使用下划线。你们有什么建议?

REST 不关心你对标识符使用什么拼写。

PUT /abff1822-71aa-4147-9b91-18a8a4f1bf6c
Content-Type: application/json
true
PUT /abff1822-71aa-4147-9b91-18a8a4f1bf6c
Content-Type: application/json
false
GET /abff1822-71aa-4147-9b91-18a8a4f1bf6c

老派的 POST 也"只是工作">

POST /abff1822-71aa-4147-9b91-18a8a4f1bf6c
Content-Type:application/x-www-form-urlencoded
value=true

URI很像变量名称 - 机器不关心,因为它们不在乎,所以你可以遵循任何有意义的本地拼写约定。

最新更新