Links Representations together.

hypermedia的Python项目详细描述


“restapi必须是超文本驱动的”,roy t.fielding

VersionDownloadsStatusLicense

等等…为什么?

“为什么”很简单…有很多框架 通过为数据库生成确定的url,使事情restful 物体。然后实现流行的http方法来提供 与新开发的资源交互的方式。恭喜你,你 已成功将SQL映射到HTTP。url已成为您的WHERE 子句和PUTPOSTGETUPDATE的同义词, INSERTSELECT

所以这是一个非常言不由衷的回答为什么我觉得有必要 编写这个库。然而,这不是一个很好的答案,甚至不是一个 在我看来是可以接受的。为什么why比这更微妙。 我刚才大声疾呼的实现可能真的很平静 但我们需要了解的不仅仅是它的url结构和如何 在我们做出决定之前,它解释了各种协议操作。 这不是一篇关于表象状态转移的论文 建筑原则,我把它留给Dr. Fielding。这个图书馆 尝试提供一些机制来开发restful协议 更简单。

什么?

这个库提供了简化restful服务编写的功能。 在现有的HTTP服务器堆栈上实现,如FlaskTornado。http栈为 构造url并将http请求路由到特定的代码块。我是 不会再实施了。相反,这个库提供了 在响应中嵌入超媒体控件而不引入大量 你的应用程序代码中的严重耦合。

这个库本质上是支持超媒体控件的入口 在您的http应用程序中。超媒体控件引用已知内容 作为Richardson Maturity Model的级别3。这个模型被描述 2008年,伦纳德·理查森在qcon接受了进一步的检查。 吉姆·韦伯最出色的作品。这里有一个简短的概述:

零级

One URL, one HTTP method - ^{tt3}$. Document describes the function to invoke, parameters, etc. Response is the return value.

“There’s a little web-based peephole into some other universe, and you can only communicate wit the other universe by passing messages through the peephole.” - L. Richardson.

level one:资源

URLs identify resources but interactions are limited to sending a message that describes the function to invoke, parameters, etc. The interactions with different resources instances usually depend on URL patterns.

二级:http

Resources are still identified by constructed URLs but interactions follow the rules of HTTP with respect to its verbs (methods). This is where most RESTful APIs stop.

三级:超媒体控件

This is where the seldom understood and inpronouncable term HATEOAS shows up. Instead of the URL being formulated by the user of the service based on what they want to do and some URL pattern syntax, the available actions are represented directly in the document as named links. See REST APIs must by hypertext-driven for a well-written and relatively short rationale.

这就是这个图书馆试图填补的故事的一部分。它 允许您编写如下代码:

from hypermedia.tornado import mixins
from tornado import web


class PersonHandler(mixins.Linker, web.RequestHandler):

   def get(self, uid):
      person = get_person_information(uid)
      self.add_link('related-shows', SearchHandler, 'GET',
                    person_id=uid, type='shows')
      self.add_link('related-movies', SearchHandler, 'GET',
                    person_id=uid, type='movies')
      self.add_link('add-comment', CommentHandler, 'POST', uid=uid)
      self.add_link('comments', CommentHandler, 'GET', uid=uid)

      response = {}
      # ... build out the response
      response['links'] = self.get_link_map()

      self.write(response)

class SearchHandler(web.RequestHandler):

   def get(self):
      # processes query parameters

class CommentHandler(web.RequestHandler):

   def get(self, uid):
      # retrieve comments

   def post(self, uid):
      # add a comment

hypermedia.tornado.mixins.Linker类负责构造 基于注册的处理程序的适当链接,并使它们 可通过get_link_map()方法获得。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java我的int值在SharedReferences中不被记住   java如何编辑Spring可分页对象?   java如何在gradle中单独调用任务   jvm以编程方式设置最大java堆大小   java如果满足多个条件,如何使用If语句计算数字?   如何在java中从json文件中获取特定值   如何在Sphinx4中为Java语音识别添加自定义语法?   java int[]copy=data;//当数据是数组时会发生什么?   java豪猪管理器。停下来。destroy()不起作用   安卓在API级别28中找不到画布变量   基于SOLID的java冗余   用于talend作业的java Liferay和portlet   从java到安卓的视频流   java获取在控件的类定义中添加自定义控件的场景大小   awt Java IndexOutOfBoundsException   java如何使用Spring JmsTemplate更改MQ头   java遍历数组并打印每个对象   java Google Map api v2标记在我旋转手机和地图“刷新”之前不会移动