问题描述
我试图设计一个RESTful API,在这里用户可以在一个GET请求获取产品的单品或列表。每个产品都有一个唯一的ID。
I'm trying to design a RESTful API where the users can fetch a single product or list of products in a single GET request. Each product has a unique id.
该单品的网址是很简单的:
The single product URL is simple enough:
http://mycompany.com/api/v1/product/id
这将返回单一产品的信息。我很困惑,多个产品信息的URL应该怎么样子。
This returns the information for a single product. I'm confused as to how the URL for multiple product information should look like.
关于
http://mycomapny.com/api/v1/product/ids
其中IDS是一个逗号分隔的ID列表?
where ids is a comma separated list of ids?
推荐答案
您用逗号分隔的足够好IDS的建议。
Your suggestion of ids separated with commas is good enough.
这将是有益的探讨一些公共REST API的,看看他们如何处理。对于前夫的StackExchange API分离用分号IDS - https://api.stackexchange.com/docs/answers-by-ids
It would be instructive to examine some public REST APIs to see how they handle. For ex, the StackExchange API separates ids with a semi-colon - https://api.stackexchange.com/docs/answers-by-ids
这篇关于REST API:在一个GET请求多个资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!