Created
May 21, 2016 07:49
-
-
Save tnishinaga/52764c59f663a0f00eac0942482ff33c to your computer and use it in GitHub Desktop.
RubyでGETに対しJSON返すだけのサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "json" | |
hoge = { | |
"hoge" => "fuga" | |
}.to_json | |
require 'webrick' | |
srv = WEBrick::HTTPServer.new({:BindAddress => '127.0.0.1', | |
:Port => 10080}) | |
srv.mount_proc("/") { |req, res| | |
res.body = hoge | |
res["Content-Type"] = "application/json" | |
} | |
Signal.trap(:INT){ srv.shutdown } | |
srv.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment