JSON的微服务架构:Satz
Satz是一个框架用于编写微服务用于服务读取JSON。它使用Syro来路由请求。可以查看Syro教程 来学习更多关于路由是如何工作的。
用法
An example of a Satz application would look like this:
App = Satz.define do on "players" do on :player_id do get do @player = Player[inbox[:player_id]] reply @player end end get do reply Player.all.to_a end post do @player = Player.new(read) on @player.valid? do @player.create reply @player end default do reply @player.errors end end end end
The argument toreplyis served as JSON by callingJSON.dump(arg). In user defined objects, you can define the methodto_jsonaccording to your needs. Most ORMs already provide meaningful definitions for that method.
API
Apart from Syro's API, the following methods are available:
read: Reads the body of the request and parses it as JSON.
reply: Writes to the response its argument encoded as JSON.
安装
$ gem install satz
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!