Skip to content

Commit 1c29253

Browse files
committed
Merge pull request ruby-grape#163 from jch/default_format_json
Default format json
2 parents b894c4c + c4ac6c1 commit 1c29253

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ group :development, :test do
1010
gem 'rb-fsevent'
1111
gem 'growl'
1212
gem 'json'
13+
gem 'debugger'
1314
end

README.markdown

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ You can also set the default format. The order for choosing the format is the fo
310310
* Use the format, if specified by the `format` option.
311311
* Attempt to find an acceptable format from the `Accept` header.
312312
* Use the default format, if specified by the `default_format` option.
313-
* Default to `:txt` otherwise.
313+
* Default to `:json` otherwise.
314314

315315
``` ruby
316316
class Twitter::API < Grape::API
@@ -319,6 +319,16 @@ class Twitter::API < Grape::API
319319
end
320320
```
321321

322+
By default, Grape understands the following content types:
323+
324+
```ruby
325+
:xml => 'application/xml',
326+
:json => 'application/json',
327+
:atom => 'application/atom+xml',
328+
:rss => 'application/rss+xml',
329+
:txt => 'text/plain'
330+
```
331+
322332
## Writing Tests
323333

324334
You can test a Grape API with RSpec by making HTTP requests and examining the response.

lib/grape/middleware/formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Formatter < Base
77

88
def default_options
99
{
10-
:default_format => :txt,
10+
:default_format => :json,
1111
:formatters => {},
1212
:content_types => {},
1313
:parsers => {}

spec/grape/middleware/formatter_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ def to_xml
7070

7171
it 'should use the default format if none is provided' do
7272
subject.call({'PATH_INFO' => '/info'})
73-
subject.env['api.format'].should == :txt
73+
subject.env['api.format'].should == :json
7474
end
7575

7676
it 'should use the requested format if provided in headers' do
77-
subject.call({'PATH_INFO' => '/info', 'HTTP_ACCEPT' => 'application/json'})
78-
subject.env['api.format'].should == :json
77+
subject.call({'PATH_INFO' => '/info', 'HTTP_ACCEPT' => 'text/plain'})
78+
subject.env['api.format'].should == :txt
7979
end
8080

8181
it 'should use the file extension format if provided before headers' do
82-
subject.call({'PATH_INFO' => '/info.txt', 'HTTP_ACCEPT' => 'application/json'})
82+
subject.call({'PATH_INFO' => '/info.txt', 'HTTP_ACCEPT' => 'text/plain'})
8383
subject.env['api.format'].should == :txt
8484
end
8585

0 commit comments

Comments
 (0)