如何构建一个 REST API 来获取资源的 id 数组 [英] How to construct a REST API that takes an array of id's for the resources
本文介绍了如何构建一个 REST API 来获取资源的 id 数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为我的项目构建 REST API.获取给定用户信息的 API 是:
I am building a REST API for my project. The API for getting a given user's INFO is:
api.com/users/[USER-ID]
我还想允许客户端传入用户 ID 列表.如何构建 API 以使其具有 RESTful 风格并接受用户 ID 列表?
I would like to also allow the client to pass in a list of user IDs. How can I construct the API so that it is RESTful and takes in a list of user ID's?
推荐答案
如果您在 URL 上传递所有参数,那么逗号分隔值可能是最佳选择.然后您将拥有一个如下所示的 URL 模板:
If you are passing all your parameters on the URL, then probably comma separated values would be the best choice. Then you would have an URL template like the following:
api.com/users?id=id1,id2,id3,id4,id5
这篇关于如何构建一个 REST API 来获取资源的 id 数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文