Rack middleware that converts Ruby objects into xml or json based on Accepts header
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib
test
vendor/xml_serialization
.document
.gitignore
LICENSE
README.rdoc
Rakefile
VERSION
config.ru
raccept.gemspec

README.rdoc

Raccept (Rack Accepts Helper)

Converts Ruby objects to JSON or XML based on accepts headers.

Ignores legal Rack responses like “string” and [“string”,“string”]

Install

gem install raccept

Use

# in config.ru
use Raccept
run lambda {|env| [200,{"Content-Type" => "text/plain"}, {:this => 'is a Hash'} ] }

# Will respond with ...
# Accepts application/xml or text/xml
<?xml version="1.0" encoding="UTF-8"?>
<hash>
  <this>is a Hash</this>
</hash>

# Accepts application/json or text/json
{"this":"is a Hash"}

Todo, maybe

  • Get something leaner than ActiveSupport for to_xml?

  • Support custom objects somehow?

  • Add tests for it.

Copyright

Copyright © 2009 Sam Schenkman-Moore. See LICENSE for details.