Skip to content

Commit 83461a1

Browse files
committed
Updated docs with parameters, headers, versioning and mounting.
1 parent 309321c commit 83461a1

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

README.markdown

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,23 @@ In a Rails application, modify *config/routes*:
9797
```ruby
9898
mount Twitter::API => "/"
9999
```
100+
You can mount multiple API implementations inside a single one.
101+
102+
```ruby
103+
class Twitter::API < Grape::API
104+
mount Twitter::APIv1
105+
mount Twitter::APIv2
106+
end
107+
```
100108

101109
## Versioning
102110

103-
Versioning is handled with HTTP Accept head by default, but can be configures
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
106-
request:
111+
There are two stragies in which clients can reach your API's endpoints: `:header`
112+
and `:path`. The default strategy is `:header`.
113+
114+
version 'v1', :using => :header
115+
116+
Using this versioning strategy, clients should pass the desired version in the HTTP Accept head.
107117

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

@@ -112,8 +122,35 @@ supplied. This behavior is similar to routing in Rails. To circumvent this defau
112122
one could use the `:strict` option. When this option is set to `true`, a `404 Not found` error
113123
is returned when no correct Accept header is supplied.
114124

115-
Serialization takes place automatically. For more detailed usage information,
116-
please visit the [Grape Wiki](http://github.com/intridea/grape/wiki).
125+
version 'v1', :using => :path
126+
127+
Using this versioning strategy, clients should pass the desired version in the URL.
128+
129+
curl -H http://localhost:9292/v1/statuses/public_timeline
130+
131+
Serialization takes place automatically.
132+
133+
## Parameters
134+
135+
Parameters are available through the `params` hash object. This include `GET` and `POST` parameters,
136+
along with any named parameters you specify in your route strings.
137+
138+
```ruby
139+
get do
140+
Article.order(params[:sort_by])
141+
end
142+
```
143+
144+
## Headers
145+
146+
Headers are available through the `env` hash object.
147+
148+
```ruby
149+
get do
150+
error! 'Unauthorized', 401 unless env['HTTP_SECRET_PASSWORD'] == 'swordfish'
151+
...
152+
end
153+
```
117154

118155
## Helpers
119156

0 commit comments

Comments
 (0)