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

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

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/6413077/rails-3-custom-route-that-takes-multiple-ids-as-a-parameter\">Rails 3自定义路由需要多个ID作为参数

据我了解,一个良好的休息网址获取资源是这样的:

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

/resource/{id}

我的问题是,我经常需要在同时得到资源的大量 并不愿意做出的单独的HTTP呼叫作为其中的每一个。

有一个整洁的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

创建具有许多标识符在一个网址限制高速缓存的优点和增加了不必要的复杂性服务器和客户端的复合网址。当您加载一个网页,有一堆图形,你看不到

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

这仅仅是不值得冒这个险。

It just isn't worth the hassle.

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

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