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