javascript - 实现复杂的 REST 调用的好习惯是什么?
问题描述
我目前正在使用 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}
解决方案
正如你所说,你有 4 个参数来计算直线。然后,您将对直线资源使用 HTTP 查询参数。然后:
http://hostname/beeline?start_lon={start_lon}&start_lat={start_lat}&end_lon={end_lon}&end_lat={end_lat}
这样,参数会改变访问直线资源的方式。
推荐阅读
- node.js - elasticsearch js更新索引
- scala - Key-Value RDD:为什么相同的重复值元组?(斯卡拉)
- vue.js - 如何在 vue-router 中同时保护 '/login' 或 '/login/' 和 '/dashboard' 或 '/dashboard/'
- r - 当执行顺序很重要时,如何加快 for 循环?
- c++11 - 模板的模板特化
- python - 如何从 CVS 文件的数据列中删除最后一个字符?
- python - 使用 Python 读取具有给定结构定界的文本文件
- python - 我应该如何编写带有数字扩展名的函数?
- java - Spring kafka NonResponsiveConsumerEvent 甚至在代理关闭时触发时间
- r - 如何在R中的字符串之间找到相同的短语