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


热门话题
如何为我的jsp/java web项目实现使用twitter登录   java KeyListener是否停止使用动作或鼠标Listener?   java Android:RecyclerView表现为GridLayout   java Appassembler在生成的脚本中构建错误的类路径   Java 11 JLink获取错误:自动模块不能与JLink:com一起使用。微软sqlserver。来自文件的jdbc   java如何检查Android tabview中打开的选项卡   java非固定大小Fenwick树实现   java如何使用java8的completableFuture实现forEach列表循环   java如何在Eclipse中指定测试类路径   java我们可以中断一个已经获得锁的线程吗?   java使用JSONPATH规范化嵌套json   在java中创建异常列表