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 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!