@@ -69,22 +69,25 @@ class Twitter::API < Grape::API
6969 end
7070
7171 resource :account do
72- before{ authenticate! }
72+ before { authenticate! }
7373
7474 get ' /private' do
7575 " Congratulations, you found the secret!"
7676 end
7777 end
78+
7879end
7980```
8081
8182## Mounting
8283
83- The above sample creates a Rack application that can be run from a rackup * config.ru* file:
84+ The above sample creates a Rack application that can be run from a rackup * config.ru* file
85+ with ` rackup ` :
8486
8587``` ruby
8688run Twitter ::API
8789```
90+
8891And would respond to the following routes:
8992
9093 GET /statuses/public_timeline(.json)
@@ -97,7 +100,7 @@ In a Rails application, modify *config/routes*:
97100``` ruby
98101mount Twitter ::API => " /"
99102```
100- You can mount multiple API implementations inside a single one.
103+ You can mount multiple API implementations inside another one.
101104
102105``` ruby
103106class Twitter ::API < Grape ::API
@@ -132,7 +135,7 @@ Serialization takes place automatically.
132135
133136## Parameters
134137
135- Parameters are available through the ` params ` hash object. This include ` GET ` and ` POST ` parameters,
138+ Parameters are available through the ` params ` hash object. This includes ` GET ` and ` POST ` parameters,
136139along with any named parameters you specify in your route strings.
137140
138141``` ruby
@@ -247,14 +250,18 @@ class Twitter::API < Grape::API
247250end
248251```
249252
250- class Twitter::API < Grape::API
251- rescue_from ArgumentError do |e|
252- Rack::Response.new([ "ArgumentError: #{e.message}" ], 500)
253- end
254- rescue_from NotImplementedError do |e|
255- Rack::Response.new([ "NotImplementedError: #{e.message}" ], 500)
256- end
257- end
253+ Or rescue specific exceptions.
254+
255+ ``` ruby
256+ class Twitter ::API < Grape ::API
257+ rescue_from ArgumentError do |e |
258+ Rack ::Response .new ([ " ArgumentError: #{ e.message } " ], 500 )
259+ end
260+ rescue_from NotImplementedError do |e |
261+ Rack ::Response .new ([ " NotImplementedError: #{ e.message } " ], 500 )
262+ end
263+ end
264+ ```
258265
259266## Content-Types
260267
@@ -296,6 +303,13 @@ describe Twitter::API do
296303 JSON .parse(response.body).should == []
297304 end
298305 end
306+ describe " GET /api/v1/statuses/:id" do
307+ it " returns a status by id" do
308+ status = Status .create!
309+ get " /api/v1/statuses/#{ status.id } "
310+ resonse.body.should == status.to_json
311+ end
312+ end
299313end
300314```
301315
0 commit comments