Skip to content

Commit a2e36d1

Browse files
author
Michael Bleigh
committed
Merge pull request ruby-grape#130 from dblock/frontier-readme-mounting
Frontier: clarified readme on mounting grape, ran spellchecker.
2 parents d66159b + ba026c5 commit a2e36d1

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

README.markdown

Lines changed: 24 additions & 12 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,39 @@ 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 sample creates a Rack application that can be run from a rackup *config.ru* file:
7984

8085
```ruby
8186
run Twitter::API
8287
```
83-
8488
And would respond to the following routes:
8589

8690
GET /statuses/public_timeline(.json)
8791
GET /statuses/home_timeline(.json)
8892
GET /statuses/show/:id(.json)
8993
POST /statuses/update(.json)
9094

95+
In a Rails application, modify *config/routes*:
96+
97+
```ruby
98+
mount Twitter::API => "/"
99+
```
100+
101+
## Versioning
102+
91103
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
104+
to [use different strategies](https://github.com/intridea/grape/wiki/API-Versioning).
105+
For example, to request the above with a version, you would make the following
95106
request:
96107

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

99110
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.
111+
supplied. This behavior is similar to routing in Rails. To circumvent this default behavior,
112+
one could use the `:strict` option. When this option is set to `true`, a `404 Not found` error
113+
is returned when no correct Accept header is supplied.
104114

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

212222
## Content-Types
213223

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.
224+
By default, Grape supports _XML_, _JSON_, _Atom_, _RSS_, and _text_ content-types.
225+
Your API can declare additional types to support. Response format is determined by the
226+
request's extension or `Accept` header.
215227

216228
```ruby
217229
class Twitter::API < Grape::API
@@ -329,7 +341,7 @@ This will match all paths starting with '/urls/'. There is one caveat though:
329341
the `params[:url]` parameter only holds the first part of the request url.
330342
Luckily this can be circumvented by using the described above syntax for path
331343
specification and using the `PATH_INFO` Rack environment variable, using
332-
`env["PATH_INFO"]`. This will hold everyting that comes after the '/urls/'
344+
`env["PATH_INFO"]`. This will hold everything that comes after the '/urls/'
333345
part.
334346

335347
## Note on Patches/Pull Requests

0 commit comments

Comments
 (0)