Class: JSONServlet

Inherits:
HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/gems/json_pure-1.1.3/tools/server.rb

Constant Summary collapse

@@count =
1

Instance Method Summary collapse

Instance Method Details

#do_GET(req, res) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gems/json_pure-1.1.3/tools/server.rb', line 13

def do_GET(req, res)
  obj = {
    "TIME" => Time.now.strftime("%FT%T"),
    "foo" => "Bär",
    "bar" => "© ≠ €!",
    'a' => 2,
    'b' => 3.141,
    'COUNT' => @@count += 1,
    'c' => 'c',
    'd' => [ 1, "b", 3.14 ],
    'e' => { 'foo' => 'bar' },
    'g' => "松本行弘",
    'h' => 1000.0,
    'i' => 0.001,
    'j' => "\xf0\xa0\x80\x81",
  }
  res.body = JSON.generate obj
  res['Content-Type'] = "application/json"
end