REST API:在一个GET请求多个资源

编程入门 行业动态 更新时间:2024-10-26 20:26:59
本文介绍了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:

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请求多个资源

本文发布于:2023-10-29 12:58:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539755.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   资源   REST   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!