REST API:在一个GET请求多个资源 [英] REST api: requesting multiple resources in a single get

查看:695
本文介绍了REST API:在一个GET请求多个资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图设计一个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 - <一个href=\"https://api.stackexchange.com/docs/answers-by-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请求多个资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆