-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME
67 lines (43 loc) · 1.32 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
===== 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