【问题标题】:What is a good practice to realize complex REST calls?实现复杂的 REST 调用的好习惯是什么?
【发布时间】:2019-09-04 01:09:36
【问题描述】:

我目前正在使用 Node.js 编写一个 REST API 来计算两个地理坐标之间的直线。为了计算结果,我需要以下 4 个参数:

  • start_lon
  • start_lat
  • end_lon
  • end_lat

所以,我的电话应该是这样的:

http://hostname/beeline/{start_lon}/{start_lat}/{end_lon}/{end_lat}

或者更多这样的:

http://hostname/beeline?start_lon={start_lon}&start_lat={start_lat}&end_lon={end_lon}&end_lat={end_lat}

【问题讨论】:

    标签: javascript rest http https


    【解决方案1】:

    正如你所说,你有 4 个参数来计算直线。然后,您将对直线资源使用 HTTP 查询参数。那么:

    http://hostname/beeline?start_lon={start_lon}&start_lat={start_lat}&end_lon={end_lon}&end_lat={end_lat}
    

    这样,参数可变获取beeline资源的方式。

    【讨论】:

      【解决方案2】:

      我会选择后者,因为参数之间没有层次关系(例如与 /images/123 相比,其中图像编号 123 在“下”,在层次意义上,“图像”文件夹)

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-07-17
        • 1970-01-01
        • 1970-01-01
        • 2011-08-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-23
        相关资源
        最近更新 更多