jopen 4年前

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.


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