REST api:在一次获取中请求多个资源 [英] REST api: requesting multiple resources in a single get

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

问题描述

我正在尝试设计一个 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.

单品网址足够简单:

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?

推荐答案

你的 id 用逗号分隔的建议已经足够好了.

Your suggestion of ids separated with commas is good enough.

检查一些公共 REST API 以了解它们如何处理是有益的.例如,StackExchange API 用分号分隔 ID - https://api.stackexchange.com/docs/id 答案

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:在一次获取中请求多个资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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