sinatraのサンプルコード

http://www.sinatrarb.com/intro-jp.html
How to: Return JSON from Sinatra - Nathan Hoad

シンプルさを追求した感じのライブラリ。
"SinatraRubyで下記のような最小労力で手早くウェブアプリケーションを作成するためのDSLです。"ですって。

以下サンプル。

# -*- encoding: utf-8 -*-
#JsonPrinter.rb
#実行>ruby -rubygems JsonPrinter.rb

require 'sinatra'
require 'json'		#json出力用gem

#他にpost等のメソッドも用意されている
#ローカルで動かす際はlocalhost:4567/here.jsonで見る
get '/here.json' do
	
	#文字コード指定してやらないと日本語が化ける
	content_type :json, :charset => 'utf-8'
	
	#to_jsonでjsonへ変換
	{ :landmark => "スタート地点", :x => "0", :y => "0"}.to_json
end