什么是REST资源? [英] What are REST resources?

查看:583
本文介绍了什么是REST资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是REST资源以及它们如何与资源名称和资源再presentations?

我看了关于这一主题的几篇文章,但他们过于抽象,他们给我留下了更多的困惑比我以前。

在下面的网址资源?如果是,那是什么资源的名称是什么其重新presentation


  

<一个href=\"http://api.example.com/users.json?length=2&offset=5\">http://api.example.com/users.json?length=2&offset=5


该URL的GET响应应该是这个样子:

  [
   {
      编号:6,
      名称:约翰
   },
   {
      ID:7,
      名称:简
   }
]


解决方案

  

什么是资源?


  
  

一个资源是什么,这是足够重要作为一个被引用
  本身的事情。如果您的用户可能会想创建一个超文本链接
  它,使或反驳它断言,检索或缓存
  再是presentation,包括它的全部或部分参照成
  另一重presentation,对它进行注释,或执行其他操作
  它,那么你应该让一个资源。


  
  

一般,一个资源的东西,可以被存储在计算机上,并
  重新presented作为比特流:一个文档,在一个数据库中的行,或
  运行的算法的结果。一个资源可以是一个物理
  喜欢的对象一个苹果,或一个抽象的概念般的勇气,但(如
  我们在后面会看​​到)这样的资源的重新presentations一定会
  令人失望的。以下是一些可能的资源:


  
  

      
  • 软件发布的1.0.3版本

  •   
  • 软件发布的最新版本

  •   
  • 2006年10月24日
  • 第一个博客文章
      
  • 小石城的路线图,阿肯色州

  •   
  • 有关水母的一些信息

  •   
  • 有关海蜇资源的目录

  •   
  • 下一个素数1024后

  •   
  • 未来五年的素数1024后

  •   
  • 为Q42004的销售数字

  •   
  • 两个熟人之间的关系,Alice和Bob

  •   
  • 打开错误的bug数据库列表

  •   

文字是由O'Reilly出版的的RESTful Web服务

What are REST resources and how do they relate to resource names and resource representations?

I read a few articles on the subject, but they were too abstract and they left me more confused than I was before.

Is the following URL a resource? If it is, what is the name of that resource and what is its representation?

http://api.example.com/users.json?length=2&offset=5

The GET response of the URL should look something like:

[
   {
      id: 6,
      name: "John"
   },
   {
      id: 7,
      name: "Jane"
   }
]

解决方案

What’s a Resource?

A resource is anything that’s important enough to be referenced as a thing in itself. If your users might "want to create a hypertext link to it, make or refute assertions about it, retrieve or cache a representation of it, include all or part of it by reference into another representation, annotate it, or perform other operations on it", then you should make it a resource.

Usually, a resource is something that can be stored on a computer and represented as a stream of bits: a document, a row in a database, or the result of running an algorithm. A resource may be a physical object like an apple, or an abstract concept like courage, but (as we’ll see later) the representations of such resources are bound to be disappointing. Here are some possible resources:

  • Version 1.0.3 of the software release
  • The latest version of the software release
  • The first weblog entry for October 24, 2006
  • A road map of Little Rock, Arkansas
  • Some information about jellyfish
  • A directory of resources pertaining to jellyfish
  • The next prime number after 1024
  • The next five prime numbers after 1024
  • The sales numbers for Q42004
  • The relationship between two acquaintances, Alice and Bob
  • A list of the open bugs in the bug database

The text is from the O'Reilly book "RESTful Web Services".

这篇关于什么是REST资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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