如何构建一个REST API这需要ID的对资源的数组 [英] How to construct a REST API that takes an array of id's for the resources

查看:98
本文介绍了如何构建一个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,因此,它是REST风格,并采取在用户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所有的参数,那么很可能逗号分隔值将是最好的选择。然后,你就必须像下面的网址范本:

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屋!

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