首页 > 解决方案 > 实现复杂的 REST 调用的好习惯是什么?

问题描述

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

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

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}

标签: javascriptresthttphttps

解决方案


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

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

这样,参数改变访问直线资源的方式。


推荐阅读