Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.41 KB | None | 0 0
  1. require 'rack'
  2. require 'json'
  3. require "active_support/core_ext/hash/conversions"
  4.  
  5. class HelloWorld
  6.   def call(env)
  7.     req = Rack::Request.new(env)
  8.    
  9.     if req.content_type =~ /json/
  10.       resp = env.to_json
  11.     else
  12.       resp = env.to_xml
  13.     end
  14.    
  15.     return [200, {"Content-Type" => req.content_type}, [resp]]
  16.   end
  17. end
  18.  
  19. Rack::Handler::WEBrick.run(
  20.   HelloWorld.new,
  21.   :Port => 9000
  22. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement