No commit activity in last 3 years
No release in over 3 years
Rack middleware to specify an app's supported media types. Returns '406 Not Acceptable' status when unsuported type is requested.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0

Runtime

 Project Readme
===== Summary

Rack middleware to specify an app's supported media types.
Returns '406 Not Acceptable' status when unsuported type is requested.

===== Install

  gem install rack-supported-media-types

===== Example

  require 'rack'
  require 'rack/supported_media_types'

  use Rack::SupportedMediaTypes, %w( application/xml application/json )
  run App.new

  # will give you:

  GET /foo
  Accept: text/html,text/plain
  #=> 406 Not Acceptable

  GET /foo
  Accept: application/xml,text/html
  #=> 200 OK

  GET /foo
  Accept: application/json,text/html
  #=> 200 OK

see examples/simple.ru for example code.

===== Tip

To read the requested type from the url's extension instead of the Accept
header (which is a more realistic use case), use Rack::AbstractFormat before
Rack::SupportedMediaTypes.

  # gem install rack-abstract-format

  require 'rack'
  require 'rack/abstract_format'
  require 'rack/supported_media_types'

  use Rack::AbstractFormat
  use Rack::SupportedMediaTypes, %w( application/xml application/json )
  run App.new

  # will result in:

  GET /foo.html
  #=> 406 Not Acceptable

  GET /foo.xml
  #=> 200 OK

  GET /foo.json
  #=> 200 OK

see examples/recommended.ru for example code.

===== Links

code:: http://github.com/mynyml/rack-supported-media-types
docs:: http://docs.github.com/mynyml/rack-supported-media-types