REST URL 设计 - 一次 HTTP 调用中的多个资源 [英] REST URL design - multiple resources in one HTTP call

查看:27
本文介绍了REST URL 设计 - 一次 HTTP 调用中的多个资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
Rails 3 自定义路由,将多个 id 作为一个参数

据我所知,用于获取资源的良好 REST URL 如下所示:

From what I understand, a good REST URL for getting a resource would look like this:

/resource/{id}

我的问题是,我经常需要同时获取大量的资源,并且不想制作单独的HTTP为每个人打电话.

The problem I have is, that I often need to get a large number of resources at the same time and do not want to make a separate HTTP call for each one of them.

是否有一个简洁的 URL 设计可以满足这一点,或者这只是不适合 REST API?

Is there a neat URL design that would cater for that or is this just not suitable for a REST API?

推荐答案

根据您的回答,您的问题的答案是创建一个包含该单组信息的新资源.例如

Based on your response, the answer to your question is to create a new resource that contains that single set of information. e.g.

GET /Customer/1212/RecentPurchases

创建在单个 url 中具有多个标识符的复合 url 会限制缓存的好处,并给服务器和客户端增加不必要的复杂性.当你加载一个有一堆图形的网页时,你看不到

Creating composite urls that have many identifiers in a single url limits the benefits of caches and adds unnecessary complexity to the server and client. When you load a web page that has a bunch of graphics, you don't see

GET /MyPage/image1.jpg;image2.jpg;image3.jpg

这不值得麻烦.

这篇关于REST URL 设计 - 一次 HTTP 调用中的多个资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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