Skip to content

Commit f0d03c2

Browse files
committed
Clarified mounting in Rails and Rack.
1 parent 6d8793f commit f0d03c2

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

README.markdown

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Grape is available as a gem, to install it just install the gem:
2121

2222
gem install grape
2323

24+
If you're using Bundler, add the gem to Gemfile.
25+
26+
gem 'grape'
27+
2428
## Basic Usage
2529

2630
Grape APIs are Rack applications that are created by subclassing `Grape::API`.
@@ -74,33 +78,40 @@ class Twitter::API < Grape::API
7478
end
7579
```
7680

77-
This would create a Rack application that could be used like so (in a Rackup
78-
config.ru file):
81+
## Mounting
82+
83+
The above exmaple would create a Rack application that could be used like so (in a Rackup
84+
*config.ru* file):
7985

8086
```ruby
8187
run Twitter::API
8288
```
83-
8489
And would respond to the following routes:
8590

8691
GET /statuses/public_timeline(.json)
8792
GET /statuses/home_timeline(.json)
8893
GET /statuses/show/:id(.json)
8994
POST /statuses/update(.json)
9095

96+
Modify *config/routes* to mount Grape in a Rails 3 application.
97+
98+
```ruby
99+
mount Twitter::API => "/"
100+
```
101+
102+
## Versioning
103+
91104
Versioning is handled with HTTP Accept head by default, but can be configures
92-
to [use different
93-
strategies](https://github.com/intridea/grape/wiki/API-Versioning). For
94-
example, to request the above with a version, you would make the following
105+
to [use different strategies](https://github.com/intridea/grape/wiki/API-Versioning).
106+
For example, to request the above with a version, you would make the following
95107
request:
96108

97109
curl -H Accept=application/vnd.twitter-v1+json http://localhost:9292/statuses/public_timeline
98110

99111
By default, the first matching version is used when no Accept header is
100-
supplied. This behavior is similar to routing in Rails.
101-
To circumvent this default behaviour, one could use the `:strict` option. When
102-
this option is set to `true`, a `404 Not found` error is returned when no
103-
correct Accept header is supplied.
112+
supplied. This behavior is similar to routing in Rails. To circumvent this default behaviour,
113+
one could use the `:strict` option. When this option is set to `true`, a `404 Not found` error
114+
is returned when no correct Accept header is supplied.
104115

105116
Serialization takes place automatically. For more detailed usage information,
106117
please visit the [Grape Wiki](http://github.com/intridea/grape/wiki).
@@ -211,7 +222,9 @@ end
211222

212223
## Content-Types
213224

214-
By default, Grape supports _XML_, _JSON_, _Atom_, _RSS_, and _text_ content-types. Your API can declare additional types to support. Response format is determined by the request's extension or `Accept` header.
225+
By default, Grape supports _XML_, _JSON_, _Atom_, _RSS_, and _text_ content-types.
226+
Your API can declare additional types to support. Response format is determined by the
227+
request's extension or `Accept` header.
215228

216229
```ruby
217230
class Twitter::API < Grape::API

0 commit comments

Comments
 (0)