硬核干货——《中小企业 AI 实战指南》免费下载! 了解详情
写点什么

RESTfulie:一个创建超媒体感知服务与客户端的 Gem

  • 2009-11-30
  • 本文字数:1112 字

    阅读完需:约 4 分钟

Guilherme Silveira 投稿给 InfoQ 告知了一个新的 ruby gem 包的发布,在开发超媒体感知的服务和客户端的时候使用它将非常容易。他这样说到:

关于什么是将 rest/restful 的思想运用到应用中以及它的好处是什么,已经被谈论得很多了。去年, Mark Baker 写过关于 restful 应用里的超媒体内容。还有更多关于正式定义 HATEOAS 的尝试以及它的优势的文章。尽管在创建基于 web 的服务方便有着一些很好的应用,但是它仍然缺失我们日常生活中最好的一部分超链接与超媒体内容

他接着描述了定义一个订单的例子,这一订单将经过一系列定义好的转变,比如从未结算到结算等等。它允许将各种各样的转变映射到对应的动作…

复制代码
class Order < ActiveRecord::Base
state :unpaid, :allow => [:latest, :pay, :cancel]
state :cancelled, :allow => :latest
transition :latest, {:action => :show}
transition :cancel, {:action => :destroy}, :cancelled
transition :pay, {}, :preparing
end

它将会生成诸如这样的一个基于 atom 的嵌入超媒体的资源表示:

复制代码
<order>
<product>basic rails course</product>
<product>RESTful training</product>
<atom:link xmlns:atom="http://www.w3.org/2005/Atom"
href="http://www.caelum.com.br/orders/1" rel="latest" />
<atom:link xmlns:atom="http://www.w3.org/2005/Atom"
href="http://www.caelum.com.br/orders/1/pay" rel="pay" />
<atom:link xmlns:atom="http://www.w3.org/2005/Atom"
href="http://www.caelum.com.br/orders/1" rel="cancel" />
</order>

并且支持客户端调用通过消费这一资源表示而动态创建的方法:

复制代码
order = Order.from_web 'http://caelum.com.br/orders/1'
order.pay(payment)

Jim Webber ,他的 RESTBucks 文章和马上发布的 REST 著作启发了这一 gem 的创建,对此表示到

智多星 Guilherme Silveira 和 Adriano Almeida,Lucas Cavalcanti 一道,在 RESTful 服务的前沿掀起了风暴。[…] 更为重要的是,他们编写了一个通用的能够用于探寻这一协议的客户端。他们的样例服务托管于 GAE,并且在 GitHub 上发布了代码让大家参与。你们干得太棒了,并且非常及时。

Savas Parastatidis ,这本书的合著者,对此有如下的评论

I can’t wait for our book to finish so that everyone can check out our discussion of hypermedia and the stuff we’ve built. It’s really great to see Restfulie taking a very similar approach to ours.

关于这一 gem 用于创建 RESTful 服务和消费这些服务的客户端的具体例子可以在 GitHub 项目存储获得。

查看英文原文: RESTfulie - A Gem To Create Hypermedia Aware Services And Clients

2009-11-30 06:182050
用户头像

发布了 133 篇内容, 共 43.2 次阅读, 收获喜欢 1 次。

关注

评论

发布
暂无评论
发现更多内容

Android开发之Theme、Style探索及源码浅析,音视频小程序开发

android 程序员 移动开发

Android开发北漂 8 年,飘飘飘 飘够了。,android开发艺术探索笔记

android 程序员 移动开发

Android干货---丢掉你老旧的参数传递方式,投入Bracer的怀抱吧。

android 程序员 移动开发

Android应用保活实践,做了6年的Android

android 程序员 移动开发

Android平台Camera开发实践指南,【大牛疯狂教学】

android 程序员 移动开发

Android庞大的源码体系是怎么设计的?2020字节跳动Framework 高频面试题详细总结

android 程序员 移动开发

Android开发人员不得不收集的代码(持续更新中),重磅来袭

android 程序员 移动开发

Android应用开发者面试时HR是怎样试出你的真实水平!(1)

android 程序员 移动开发

Android应用开发者面试时HR是怎样试出你的真实水平!,大厂Android开发面试解答

android 程序员 移动开发

Android开发已经到了要烧香求职的地步了?,Android程序员的春天

android 程序员 移动开发

Android开发必看:一文教你完全理解DataBinding框架(上

android 程序员 移动开发

Android应届毕业生“过五关斩六将”,移动端开发技术

android 程序员 移动开发

Android开发最担心,在乎的三个问题!你有几个,android直播原理

android 程序员 移动开发

Android开发没有一技之长就废了吗?,flutter通知推送

android 程序员 移动开发

Android开发简记:140M到67M,学而思网校如何在一周内构建一套可持续的瘦身系统

android 程序员 移动开发

Android开发38岁被裁,本以为稳进Top3,今天已经是失业第42天

android 程序员 移动开发

Android开发失业50天,面了10家公司,唯二的offer也主动拒了

android 程序员 移动开发

Android开发必看:一文教你完全理解DataBinding框架(下

android 程序员 移动开发

Android开发简记:探索App性能优化之Android内存泄漏,想跳槽涨薪的必看

android 程序员 移动开发

Android开发项目实战:实现折叠式布局,2021年是做Android开发人员的绝佳时机

android 程序员 移动开发

Android平台HTTPS抓包解决方案及问题分析,flutter弹窗效果

android 程序员 移动开发

Android应用开发性能优化完全分析,flutter蓝牙开发

android 程序员 移动开发

Android庞大的源码体系是怎么设计的?2020字节跳动Framework-高频面试题详细总结

android 程序员 移动开发

Android开发把-LiveData-用于事件传递那些坑,一文详解

android 程序员 移动开发

Android应用启动流程分析,10天拿到字节跳动Android岗位offer

android 程序员 移动开发

Android应用开发进阶,android开发从入门到精通项目案例版

android 程序员 移动开发

Android开发1年背了几十份面经还是连挂了6个面试,拿到最终字节腾讯offer后我总结了这些坑点

android 程序员 移动开发

Android开发三年半5月份离职,面试10家公司后,这些面试官常问的面试题一定要了解

android 程序员 移动开发

Android开发之旅:HelloWorld项目的目录结构,1个月学会Android开发

android 程序员 移动开发

Android开发者必看的GitHub-上-10-个顶级开源项目,android开发基础机构

android 程序员 移动开发

Android常见原理性面试题,android高级开发面试题以及答案

android 程序员 移动开发

RESTfulie:一个创建超媒体感知服务与客户端的Gem_SOA_Dilip Krishnan_InfoQ精选文章