地设计出多个过滤器REST API
问题说明
作为个人的编程项目,我的工作我的刮大学的课程目录,并为REST API提供的数据。我已经成功地刮的所有数据,并存储在数据库中,和我现在工作的API。
As a personal programming project, I am working on scraping my University's course catalog and providing the data as a REST API. I have successfully scraped all the data and stored it in a database, and am now working on the API.
这些课程可以多种标准的基础上进行过滤:教练,大学,学分,时间,日期等。
The courses can be filtered on the basis of many criteria: instructor, college, credits, time, day etc.
什么是在这种情况下提供了一个API的最佳方式?
What is the best way to provide an API in this situation?
选项1
提供众多的URL,如
example.com/api/byinstructor/<instructor$c$c>
example.come / API / bycollege /&LT;大专code&GT;
example.com/api/bycollegeandinstructor/<college$c$c>/<instructor$c$c>
...等等
我需要对所有排列的URL。这似乎很繁琐,无论是对我和API消费者,并非常不干燥。
I would need to have a URL for all permutations. This seems very cumbersome, both for me and the API consumers, and very un-DRY.
选项2
只有像的主要选项提供的API:
Only provide APIs for the major options like:
example.com/api/byinstructor/<instructor$c$c>
example.come / API / bycollege /&LT;大专code&GT;
如果消费者想要 bycollegeandinstructor
,他是不是最终的过滤。
And if the consumer wants bycollegeandinstructor
, he does the filtering on his end.
选项3
用户通过JSON字符串给我,我用它来获取过滤标准
The user passes a JSON string to me, and I use that to get the filtering criteria
example.com/api/getcourses/<jsonstring>
jsonstring =
{
instructor:<instructorcode>,
college:<collegecode>,
...and so on
}
我想,而不是JSON字符串,我也可以要求一个POST阵列,但似乎未inituitive为消费者,因为他是歌厅的数据。
I suppose instead of the Json string, I could also require a POST array, but that seems un-inituitive for the consumer since he is GETing data.
还是没有这样做,我不知道的另一种方式?如果是,是最好的选择第三个选项,可能你prepare一个JSON字符串的基础上的SQL查询提供了一个简短的总结最好的,可能有变量值的数量?
Or is there another way of doing this I am not aware of? If it is the third option that is the best option, could you provide a short summary best to prepare a SQL query on the basis of a JSOn string that may have variable number of values?
正确答案
要扩大从J.F.答案,这听起来像你有一个资源,集课程,这将是在URI:
To expand on the answer from J.F., it sounds like you have one resource, the set of courses, which would be at the URI:
/courses
过滤功能,资源通常使用查询参数来完成,以过滤单一的资源,例如:
Filtering that resource is usually accomplished using query parameters to filter that single resource, e.g:
/courses?college=123&instructor=321
通过这样做,你避免所有可能的排列创造资源的扩散问题。
By doing this, you avoid the issue with all possible permutations creating a proliferation of resources.
从根本上:有一个资源,其可以被过滤为必要
Fundamentally: There's one resource, which can be filtered as necessary.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhchabbi
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20