Skip to content

Commit e61c905

Browse files
committed
Fixed typo.
1 parent 5f5cdce commit e61c905

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

README.markdown

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Grape APIs are Rack applications that are created by subclassing `Grape::API`.
3636
Below is a simple example showing some of the more common features of Grape in
3737
the context of recreating parts of the Twitter API.
3838

39-
```ruby
39+
``` ruby
4040
class Twitter::API < Grape::API
4141
version 'v1', :using => :header, :vendor => 'twitter'
4242

@@ -87,7 +87,7 @@ end
8787

8888
The above sample creates a Rack application that can be run from a rackup *config.ru* file:
8989

90-
```ruby
90+
``` ruby
9191
run Twitter::API
9292
```
9393
And would respond to the following routes:
@@ -99,7 +99,7 @@ And would respond to the following routes:
9999

100100
In a Rails application, modify *config/routes*:
101101

102-
```ruby
102+
``` ruby
103103
mount Twitter::API => "/"
104104
```
105105

@@ -124,7 +124,7 @@ Serialization takes place automatically.
124124
You can define helper methods that your endpoints can use with the `helpers`
125125
macro by either giving a block or a module:
126126

127-
````ruby
127+
``` ruby
128128
module MyHelpers
129129
def say_hello(user)
130130
"hey there #{user.name}"
@@ -147,13 +147,13 @@ class API < Grape::API
147147
say_hello(current_user)
148148
end
149149
end
150-
````
150+
```
151151

152152
## Cookies
153153

154154
You can set, get and delete your cookies very simply using `cookies` method:
155155

156-
````ruby
156+
``` ruby
157157
class API < Grape::API
158158
get '/counter' do
159159
cookies[:counter] ||= 0
@@ -165,32 +165,32 @@ class API < Grape::API
165165
{ :result => cookies.delete(:counter) }
166166
end
167167
end
168-
````
168+
```
169169

170170
To set more than value use hash-based syntax:
171171

172-
````ruby
172+
``` ruby
173173
cookies[:counter] = {
174174
:value => 0,
175175
:expires => Time.tomorrow,
176176
:domain => '.example.com',
177177
:path => '/'
178178
}
179179
cookies[:counter][:value] +=1
180-
````
180+
```
181181

182182
## Raising Errors
183183

184184
You can raise errors explicitly.
185185

186-
```ruby
186+
``` ruby
187187
error!("Access Denied", 401)
188188
```
189189

190190
You can also return JSON formatted objects explicitly by raising error! and
191191
passing a hash instead of a message.
192192

193-
```ruby
193+
``` ruby
194194
error!({ "error" => "unexpected error", "detail" => "missing widget" }, 500)
195195
```
196196

@@ -199,15 +199,15 @@ error!({ "error" => "unexpected error", "detail" => "missing widget" }, 500)
199199
Grape can be told to rescue all exceptions and instead return them in
200200
text or json formats.
201201

202-
```ruby
202+
``` ruby
203203
class Twitter::API < Grape::API
204204
rescue_from :all
205205
end
206206
```
207207

208208
You can also rescue specific exceptions.
209209

210-
```ruby
210+
``` ruby
211211
class Twitter::API < Grape::API
212212
rescue_from ArgumentError, NotImplementedError
213213
end
@@ -216,7 +216,7 @@ end
216216
The error format can be specified using `error_format`. Available formats are
217217
`:json` and `:txt` (default).
218218

219-
```ruby
219+
``` ruby
220220
class Twitter::API < Grape::API
221221
error_format :json
222222
end
@@ -225,7 +225,7 @@ end
225225
You can rescue all exceptions with a code block. The `rack_response` wrapper
226226
automatically sets the default error code and content-type.
227227

228-
```ruby
228+
``` ruby
229229
class Twitter::API < Grape::API
230230
rescue_from :all do |e|
231231
rack_response({ :message => "rescued from #{e.class.name}" })
@@ -236,30 +236,32 @@ end
236236
You can also rescue specific exceptions with a code block and handle the Rack
237237
response at the lowest level.
238238

239-
```ruby
239+
``` ruby
240240
class Twitter::API < Grape::API
241241
rescue_from :all do |e|
242242
Rack::Response.new([ e.message ], 500, { "Content-type" => "text/error" }).finish
243243
end
244244
end
245245
```
246246

247-
class Twitter::API < Grape::API
248-
rescue_from ArgumentError do |e|
249-
Rack::Response.new([ "ArgumentError: #{e.message}" ], 500)
250-
end
251-
rescue_from NotImplementedError do |e|
252-
Rack::Response.new([ "NotImplementedError: #{e.message}" ], 500)
253-
end
254-
end
247+
``` ruby
248+
class Twitter::API < Grape::API
249+
rescue_from ArgumentError do |e|
250+
Rack::Response.new([ "ArgumentError: #{e.message}" ], 500)
251+
end
252+
rescue_from NotImplementedError do |e|
253+
Rack::Response.new([ "NotImplementedError: #{e.message}" ], 500)
254+
end
255+
end
256+
```
255257

256258
## Content-Types
257259

258260
By default, Grape supports _XML_, _JSON_, _Atom_, _RSS_, and _text_ content-types.
259261
Your API can declare additional types to support. Response format is determined by the
260262
request's extension or `Accept` header.
261263

262-
```ruby
264+
``` ruby
263265
class Twitter::API < Grape::API
264266
content_type :xls, "application/vnd.ms-excel"
265267
end
@@ -273,10 +275,10 @@ You can also set the default format. The order for choosing the format is the fo
273275
* Use the default format, if specified by the `default_format` option.
274276
* Default to `:txt` otherwise.
275277

276-
```ruby
278+
``` ruby
277279
class Twitter::API < Grape::API
278280
format :json
279-
defalt_format :json
281+
default_format :json
280282
end
281283
```
282284

@@ -287,7 +289,7 @@ must go into the `spec/request` group. You may want your API code to go into
287289
`app/api` - you can match that layout under `spec` by adding the following in
288290
`spec/spec_helper.rb`.
289291

290-
```ruby
292+
``` ruby
291293
RSpec.configure do |config|
292294
config.include RSpec::Rails::RequestExampleGroup, :type => :request, :example_group => {
293295
:file_path => /spec\/api/
@@ -297,7 +299,7 @@ end
297299

298300
A simple RSpec API test makes a `get` request and parses the response.
299301

300-
```ruby
302+
``` ruby
301303
require 'spec_helper'
302304

303305
describe Twitter::API do
@@ -317,7 +319,7 @@ Grape lets you add a description to an API along with any other optional
317319
elements that can also be inspected at runtime.
318320
This can be useful for generating documentation.
319321

320-
```ruby
322+
``` ruby
321323
class TwitterAPI < Grape::API
322324

323325
version 'v1'
@@ -342,7 +344,7 @@ contains a `route_prefix`, `route_version`, `route_namespace`, `route_method`,
342344
follows the API path may contain any number of keys and its values are also
343345
accessible via dynamically-generated `route_[name]` functions.
344346

345-
```ruby
347+
``` ruby
346348
TwitterAPI::versions # yields [ 'v1', 'v2' ]
347349
TwitterAPI::routes # yields an array of Grape::Route objects
348350
TwitterAPI::routes[0].route_version # yields 'v1'
@@ -351,7 +353,7 @@ TwitterAPI::routes[0].route_description # yields [ { "s" => { :desc => "string t
351353

352354
Parameters can also be tagged to the method declaration itself.
353355

354-
```ruby
356+
``` ruby
355357
class StringAPI < Grape::API
356358
get "split/:string", { :params => [ "token" ], :optional_params => [ "limit" ] } do
357359
params[:string].split(params[:token], (params[:limit] || 0))
@@ -364,7 +366,7 @@ StringAPI::routes[0].route_optional_params # yields an array [ "limit" ]
364366

365367
It's possible to retrieve the information about the current route from within an API call with `route`.
366368

367-
```ruby
369+
``` ruby
368370
class MyAPI < Grape::API
369371
desc "Returns a description of a parameter.", { :params => { "id" => "a required id" } }
370372
get "params/:id" do
@@ -387,7 +389,7 @@ In Grape this option can be used as well when a method is defined.
387389

388390
For instance when you're API needs to get part of an URL, for instance:
389391

390-
```ruby
392+
``` ruby
391393
class UrlAPI < Grape::API
392394
namespace :urls do
393395
get '/(*:url)', :anchor => false do

0 commit comments

Comments
 (0)