【问题标题】:API design for api which returns true or false返回 true 或 false 的 API 的 API 设计
【发布时间】:2021-10-19 10:57:23
【问题描述】:

对于接受学生 ID 列表的 API 的 API 设计应该是什么,并且客户想知道该学生中是否有任何一个不包含姓氏。

我只是对此类 API 的 rest API 设计应该是什么感到困惑,而客户端只对真假感兴趣

这里的true表示所有学生都包含姓氏

而虚假状态并非所有学生都包含姓氏。

【问题讨论】:

    标签: api-design rest


    【解决方案1】:

    对于这种情况,您可以使用简单的for,在 python 中是这样的:

    def check_user(users: list):
        result = True
        for u in users:
            if not u.has_surname():
                result = False
        data = {'result': result}
        return Response(data=data, status=200)
    

    【讨论】:

      猜你喜欢
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多