Skip to content

Instantly share code, notes, and snippets.

@tnishinaga
Created May 21, 2016 07:49
Show Gist options
  • Save tnishinaga/52764c59f663a0f00eac0942482ff33c to your computer and use it in GitHub Desktop.
Save tnishinaga/52764c59f663a0f00eac0942482ff33c to your computer and use it in GitHub Desktop.
RubyでGETに対しJSON返すだけのサンプル
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