我试图设计一个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:
mycompany/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.
关于
mycomapny/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 - api.stackexchange/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 - api.stackexchange/docs/answers-by-ids
更多推荐
REST API:在一个GET请求多个资源
发布评论