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第三方库


热门话题
使用SerializationUtils时java ClassNotFoundException。克隆()   java Cucumber+spring:如何通过测试触发SmartLifecycle事件?   java如何使ProGuard以简单的方式工作?   java JSP页面显示来自集合的日期   谷歌地图检查坐标是否位于JAVA中谷歌地图API的多边形中   java如何在终端中使用“tokens”打印令牌?   java获取编译错误:包com。威里奥。sdk不存在   java会使用JAXB或类似工具自动填充HATEAOS链接吗?   Javascript(GraalJS)与Java中未签名的右移>>>>   如何在Java代码中创建jdbc请求的Jmeter测试   java如何在CellList中添加或删除单个元素?   java Progressbar:如何创建原始对象的深度副本