grape 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -1
- data/Gemfile.lock +12 -12
- data/LICENSE +1 -1
- data/README.md +103 -23
- data/UPGRADING.md +32 -0
- data/lib/grape.rb +2 -0
- data/lib/grape/api.rb +36 -9
- data/lib/grape/api/instance.rb +25 -2
- data/lib/grape/dsl/callbacks.rb +20 -0
- data/lib/grape/dsl/desc.rb +6 -2
- data/lib/grape/dsl/inside_route.rb +12 -6
- data/lib/grape/endpoint.rb +36 -28
- data/lib/grape/middleware/error.rb +1 -2
- data/lib/grape/util/endpoint_configuration.rb +6 -0
- data/lib/grape/util/lazy_value.rb +90 -0
- data/lib/grape/validations/params_scope.rb +7 -2
- data/lib/grape/validations/validators/as.rb +2 -2
- data/lib/grape/version.rb +1 -1
- data/pkg/grape-1.2.3.gem +0 -0
- data/spec/grape/api_remount_spec.rb +235 -12
- data/spec/grape/api_spec.rb +210 -0
- data/spec/grape/endpoint_spec.rb +39 -3
- data/spec/grape/validations/params_scope_spec.rb +32 -12
- metadata +5 -3
- data/gemfiles/rails_edge.gemfile.lock +0 -335
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5943237e37e943a5a4e1d42bc6345f3af0e56509864050c7c12ba20b55d1bfb7
|
4
|
+
data.tar.gz: 3221d07199e081a570a99fcfe42706d9a4934e8e34054071992f3a6f84a75844
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 907e9a73f79bcd972ffc723215e824586875f6d10f6118ec591834a079def3aba630570c1ec3798e6e98b624b2c00e9523c4ad52821ea536873c837964cb2627
|
7
|
+
data.tar.gz: 81af4b1f525ccb23ea9c7c6975099ff37283ffafac37cbd7a43c8cc93e06b344555464554859569b7ad573960e4dca11b428f7d5b96346eba2c7361c6beb526f
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
### 1.2.
|
1
|
+
### 1.2.5 (Next)
|
2
2
|
|
3
3
|
#### Features
|
4
4
|
|
@@ -8,6 +8,19 @@
|
|
8
8
|
|
9
9
|
* Your contribution here.
|
10
10
|
|
11
|
+
### 1.2.4 (2019/06/13)
|
12
|
+
|
13
|
+
#### Features
|
14
|
+
|
15
|
+
* [#1888](https://github.com/ruby-grape/grape/pull/1888): Makes the `configuration` hash widly available - [@myxoh](https://github.com/myxoh).
|
16
|
+
* [#1864](https://github.com/ruby-grape/grape/pull/1864): Adds `finally` on the API - [@myxoh](https://github.com/myxoh).
|
17
|
+
* [#1869](https://github.com/ruby-grape/grape/pull/1869): Fix issue with empty headers after `error!` method call - [@anaumov](https://github.com/anaumov).
|
18
|
+
|
19
|
+
#### Fixes
|
20
|
+
|
21
|
+
* [#1868](https://github.com/ruby-grape/grape/pull/1868): Fix NoMethodError with none hash params - [@ksss](https://github.com/ksss).
|
22
|
+
* [#1876](https://github.com/ruby-grape/grape/pull/1876): Fix const errors being hidden by bug in `const_missing` - [@dandehavilland](https://github.com/dandehavilland).
|
23
|
+
|
11
24
|
### 1.2.3 (2019/01/16)
|
12
25
|
|
13
26
|
#### Features
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
grape (1.2.
|
4
|
+
grape (1.2.4)
|
5
5
|
activesupport
|
6
6
|
builder
|
7
7
|
mustermann-grape (~> 1.0.0)
|
@@ -12,7 +12,7 @@ PATH
|
|
12
12
|
GEM
|
13
13
|
remote: https://rubygems.org/
|
14
14
|
specs:
|
15
|
-
activesupport (5.2.
|
15
|
+
activesupport (5.2.1)
|
16
16
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
17
|
i18n (>= 0.7, < 2)
|
18
18
|
minitest (~> 5.1)
|
@@ -40,7 +40,7 @@ GEM
|
|
40
40
|
descendants_tracker (~> 0.0.1)
|
41
41
|
colored (1.2)
|
42
42
|
colored2 (3.1.2)
|
43
|
-
concurrent-ruby (1.1.
|
43
|
+
concurrent-ruby (1.1.5)
|
44
44
|
cookiejar (0.3.3)
|
45
45
|
cork (0.3.0)
|
46
46
|
colored2 (~> 3.1)
|
@@ -78,7 +78,7 @@ GEM
|
|
78
78
|
multipart-post (>= 1.2, < 3)
|
79
79
|
faraday-http-cache (1.3.1)
|
80
80
|
faraday (~> 0.8)
|
81
|
-
ffi (1.
|
81
|
+
ffi (1.9.25)
|
82
82
|
formatador (0.2.5)
|
83
83
|
git (1.5.0)
|
84
84
|
grape-entity (0.7.1)
|
@@ -102,10 +102,10 @@ GEM
|
|
102
102
|
guard (~> 2.0)
|
103
103
|
rubocop (~> 0.20)
|
104
104
|
hashie (3.6.0)
|
105
|
-
i18n (1.
|
105
|
+
i18n (1.6.0)
|
106
106
|
concurrent-ruby (~> 1.0)
|
107
107
|
ice_nine (0.11.2)
|
108
|
-
json (2.
|
108
|
+
json (2.2.0)
|
109
109
|
kramdown (1.17.0)
|
110
110
|
listen (3.1.5)
|
111
111
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
@@ -132,7 +132,7 @@ GEM
|
|
132
132
|
sawyer (~> 0.8.0, >= 0.5.3)
|
133
133
|
open4 (1.3.4)
|
134
134
|
parallel (1.12.1)
|
135
|
-
parser (2.
|
135
|
+
parser (2.5.3.0)
|
136
136
|
ast (~> 2.4.0)
|
137
137
|
powerpack (0.1.2)
|
138
138
|
pry (0.12.2)
|
@@ -150,8 +150,8 @@ GEM
|
|
150
150
|
rake
|
151
151
|
rake (12.3.2)
|
152
152
|
rb-fsevent (0.10.3)
|
153
|
-
rb-inotify (0.10
|
154
|
-
ffi (
|
153
|
+
rb-inotify (0.9.10)
|
154
|
+
ffi (>= 0.5.0, < 2)
|
155
155
|
rspec (3.8.0)
|
156
156
|
rspec-core (~> 3.8.0)
|
157
157
|
rspec-expectations (~> 3.8.0)
|
@@ -186,7 +186,7 @@ GEM
|
|
186
186
|
json (>= 1.8, < 3)
|
187
187
|
simplecov-html (~> 0.10.0)
|
188
188
|
simplecov-html (0.10.2)
|
189
|
-
term-ansicolor (1.7.
|
189
|
+
term-ansicolor (1.7.1)
|
190
190
|
tins (~> 1.0)
|
191
191
|
terminal-table (1.8.0)
|
192
192
|
unicode-display_width (~> 1.1, >= 1.1.1)
|
@@ -195,7 +195,7 @@ GEM
|
|
195
195
|
tins (1.20.2)
|
196
196
|
tzinfo (1.2.5)
|
197
197
|
thread_safe (~> 0.1)
|
198
|
-
unicode-display_width (1.4.
|
198
|
+
unicode-display_width (1.4.0)
|
199
199
|
virtus (1.0.5)
|
200
200
|
axiom-types (~> 0.1)
|
201
201
|
coercible (~> 1.0)
|
@@ -228,4 +228,4 @@ DEPENDENCIES
|
|
228
228
|
ruby-grape-danger (~> 0.1.0)
|
229
229
|
|
230
230
|
BUNDLED WITH
|
231
|
-
1.
|
231
|
+
1.17.1
|
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2010-
|
1
|
+
Copyright (c) 2010-2019 Michael Bleigh, Intridea Inc. and Contributors.
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -5,7 +5,6 @@
|
|
5
5
|
[![Code Climate](https://codeclimate.com/github/ruby-grape/grape.svg)](https://codeclimate.com/github/ruby-grape/grape)
|
6
6
|
[![Coverage Status](https://coveralls.io/repos/github/ruby-grape/grape/badge.svg?branch=master)](https://coveralls.io/github/ruby-grape/grape?branch=master)
|
7
7
|
[![Inline docs](https://inch-ci.org/github/ruby-grape/grape.svg)](https://inch-ci.org/github/ruby-grape/grape)
|
8
|
-
[![git.legal](https://git.legal/projects/1364/badge.svg "Number of libraries approved")](https://git.legal/projects/1364)
|
9
8
|
[![Join the chat at https://gitter.im/ruby-grape/grape](https://badges.gitter.im/ruby-grape/grape.svg)](https://gitter.im/ruby-grape/grape?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
10
9
|
|
11
10
|
## Table of Contents
|
@@ -20,6 +19,8 @@
|
|
20
19
|
- [ActiveRecord without Rails](#activerecord-without-rails)
|
21
20
|
- [Alongside Sinatra (or other frameworks)](#alongside-sinatra-or-other-frameworks)
|
22
21
|
- [Rails](#rails)
|
22
|
+
- [Rails < 5.2](#rails--52)
|
23
|
+
- [Rails 6.0](#rails-60)
|
23
24
|
- [Modules](#modules)
|
24
25
|
- [Remounting](#remounting)
|
25
26
|
- [Mount Configuration](#mount-configuration)
|
@@ -45,7 +46,7 @@
|
|
45
46
|
- [Validation of Nested Parameters](#validation-of-nested-parameters)
|
46
47
|
- [Dependent Parameters](#dependent-parameters)
|
47
48
|
- [Group Options](#group-options)
|
48
|
-
- [
|
49
|
+
- [Renaming](#renaming)
|
49
50
|
- [Built-in Validators](#built-in-validators)
|
50
51
|
- [allow_blank](#allow_blank)
|
51
52
|
- [values](#values)
|
@@ -74,6 +75,9 @@
|
|
74
75
|
- [Overriding Attribute Names](#overriding-attribute-names)
|
75
76
|
- [With Default](#with-default)
|
76
77
|
- [Headers](#headers)
|
78
|
+
- [Request](#request)
|
79
|
+
- [Header Case Handling](#header-case-handling)
|
80
|
+
- [Response](#response)
|
77
81
|
- [Routes](#routes)
|
78
82
|
- [Helpers](#helpers)
|
79
83
|
- [Path Helpers](#path-helpers)
|
@@ -109,7 +113,7 @@
|
|
109
113
|
- [Register custom middleware for authentication](#register-custom-middleware-for-authentication)
|
110
114
|
- [Describing and Inspecting an API](#describing-and-inspecting-an-api)
|
111
115
|
- [Current Route and Endpoint](#current-route-and-endpoint)
|
112
|
-
- [Before and
|
116
|
+
- [Before, After and Finally](#before-after-and-finally)
|
113
117
|
- [Anchoring](#anchoring)
|
114
118
|
- [Using Custom Middleware](#using-custom-middleware)
|
115
119
|
- [Grape Middleware](#grape-middleware)
|
@@ -149,9 +153,9 @@ content negotiation, versioning and much more.
|
|
149
153
|
|
150
154
|
## Stable Release
|
151
155
|
|
152
|
-
You're reading the documentation for the next release of Grape, which should be **1.2.
|
156
|
+
You're reading the documentation for the next release of Grape, which should be **1.2.5**.
|
153
157
|
Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
|
154
|
-
The current stable release is [1.2.
|
158
|
+
The current stable release is [1.2.4](https://github.com/ruby-grape/grape/blob/v1.2.4/README.md).
|
155
159
|
|
156
160
|
## Project Resources
|
157
161
|
|
@@ -322,6 +326,14 @@ run Rack::Cascade.new [API, Web]
|
|
322
326
|
|
323
327
|
Place API files into `app/api`. Rails expects a subdirectory that matches the name of the Ruby module and a file name that matches the name of the class. In our example, the file name location and directory for `Twitter::API` should be `app/api/twitter/api.rb`.
|
324
328
|
|
329
|
+
Modify `config/routes`:
|
330
|
+
|
331
|
+
```ruby
|
332
|
+
mount Twitter::API => '/'
|
333
|
+
```
|
334
|
+
|
335
|
+
#### Rails < 5.2
|
336
|
+
|
325
337
|
Modify `application.rb`:
|
326
338
|
|
327
339
|
```ruby
|
@@ -329,14 +341,18 @@ config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb')
|
|
329
341
|
config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')]
|
330
342
|
```
|
331
343
|
|
332
|
-
|
344
|
+
See [below](#reloading-api-changes-in-development) for additional code that enables reloading of API changes in development.
|
345
|
+
|
346
|
+
#### Rails 6.0
|
347
|
+
|
348
|
+
For Rails versions greater than 6.0.0.beta2, `Zeitwerk` autoloader is the default for CRuby. By default `Zeitwerk` inflects `api` as `Api` instead of `API`. To make our example work, you need to uncomment the lines at the bottom of `config/initializers/inflections.rb`, and add `API` as an acronym:
|
333
349
|
|
334
350
|
```ruby
|
335
|
-
|
351
|
+
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
352
|
+
inflect.acronym 'API'
|
353
|
+
end
|
336
354
|
```
|
337
355
|
|
338
|
-
See [below](#reloading-api-changes-in-development) for additional code that enables reloading of API changes in development.
|
339
|
-
|
340
356
|
### Modules
|
341
357
|
|
342
358
|
You can mount multiple API implementations inside another one. These don't have to be
|
@@ -396,11 +412,11 @@ class Comment::API < Grape::API
|
|
396
412
|
end
|
397
413
|
```
|
398
414
|
|
399
|
-
Assuming that the post and comment endpoints are mounted in `/posts` and `/comments`, you should now be able to do `get /posts/votes`, `post /posts/votes`, `get /comments/votes`.
|
415
|
+
Assuming that the post and comment endpoints are mounted in `/posts` and `/comments`, you should now be able to do `get /posts/votes`, `post /posts/votes`, `get /comments/votes` and `post /comments/votes`.
|
400
416
|
|
401
417
|
### Mount Configuration
|
402
418
|
|
403
|
-
You can configure remountable endpoints
|
419
|
+
You can configure remountable endpoints to change how they behave according to where they are mounted.
|
404
420
|
|
405
421
|
```ruby
|
406
422
|
class Voting::API < Grape::API
|
@@ -421,6 +437,35 @@ class Comment::API < Grape::API
|
|
421
437
|
end
|
422
438
|
```
|
423
439
|
|
440
|
+
You can access `configuration` on the class (to use as dynamic attributes), inside blocks (like namespace)
|
441
|
+
|
442
|
+
If you want logic happening given on an `configuration`, you can use the helper `given`.
|
443
|
+
|
444
|
+
```ruby
|
445
|
+
class ConditionalEndpoint::API < Grape::API
|
446
|
+
given configuration[:some_setting] do
|
447
|
+
get 'mount_this_endpoint_conditionally' do
|
448
|
+
configuration[:configurable_response]
|
449
|
+
end
|
450
|
+
end
|
451
|
+
end
|
452
|
+
```
|
453
|
+
|
454
|
+
If you want a block of logic running every time an endpoint is mounted (within which you can access the `configuration` Hash)
|
455
|
+
|
456
|
+
|
457
|
+
```ruby
|
458
|
+
class ConditionalEndpoint::API < Grape::API
|
459
|
+
mounted do
|
460
|
+
YourLogger.info "This API was mounted at: #{Time.now}"
|
461
|
+
|
462
|
+
get configuration[:endpoint_name] do
|
463
|
+
configuration[:configurable_response]
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|
467
|
+
```
|
468
|
+
|
424
469
|
## Versioning
|
425
470
|
|
426
471
|
There are four strategies in which clients can reach your API's endpoints: `:path`,
|
@@ -551,7 +596,7 @@ Currently the configurable settings are:
|
|
551
596
|
|
552
597
|
* `param_builder`: Sets the [Parameter Builder](#parameters), defaults to `Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder`.
|
553
598
|
|
554
|
-
To change a setting value make sure that at some point
|
599
|
+
To change a setting value make sure that at some point during load time the following code runs
|
555
600
|
|
556
601
|
```ruby
|
557
602
|
Grape.configure do |config|
|
@@ -559,7 +604,7 @@ Grape.configure do |config|
|
|
559
604
|
end
|
560
605
|
```
|
561
606
|
|
562
|
-
For example, for the `param_builder`, the following code could run in an
|
607
|
+
For example, for the `param_builder`, the following code could run in an initializer:
|
563
608
|
|
564
609
|
```ruby
|
565
610
|
Grape.configure do |config|
|
@@ -1202,7 +1247,7 @@ params do
|
|
1202
1247
|
end
|
1203
1248
|
```
|
1204
1249
|
|
1205
|
-
You can
|
1250
|
+
You can rename parameters:
|
1206
1251
|
|
1207
1252
|
```ruby
|
1208
1253
|
params do
|
@@ -1213,7 +1258,7 @@ params do
|
|
1213
1258
|
end
|
1214
1259
|
```
|
1215
1260
|
|
1216
|
-
Note: param in `given` should be the
|
1261
|
+
Note: param in `given` should be the renamed one. In the example, it should be `type`, not `category`.
|
1217
1262
|
|
1218
1263
|
### Group Options
|
1219
1264
|
|
@@ -1242,9 +1287,9 @@ params do
|
|
1242
1287
|
end
|
1243
1288
|
```
|
1244
1289
|
|
1245
|
-
###
|
1290
|
+
### Renaming
|
1246
1291
|
|
1247
|
-
You can
|
1292
|
+
You can rename parameters using `as`, which can be useful when refactoring existing APIs:
|
1248
1293
|
|
1249
1294
|
```ruby
|
1250
1295
|
resource :users do
|
@@ -1795,6 +1840,7 @@ end
|
|
1795
1840
|
|
1796
1841
|
## Headers
|
1797
1842
|
|
1843
|
+
### Request
|
1798
1844
|
Request headers are available through the `headers` helper or from `env` in their original form.
|
1799
1845
|
|
1800
1846
|
```ruby
|
@@ -1809,13 +1855,30 @@ get do
|
|
1809
1855
|
end
|
1810
1856
|
```
|
1811
1857
|
|
1858
|
+
#### Header Case Handling
|
1859
|
+
|
1860
|
+
The above example may have been requested as follows:
|
1861
|
+
|
1862
|
+
``` shell
|
1863
|
+
curl -H "secret_PassWord: swordfish" ...
|
1864
|
+
```
|
1865
|
+
|
1866
|
+
The header name will have been normalized for you.
|
1867
|
+
|
1868
|
+
- In the `header` helper names will be coerced into a capitalized kebab case.
|
1869
|
+
- In the `env` collection they appear in all uppercase, in snake case, and prefixed with 'HTTP_'.
|
1870
|
+
|
1871
|
+
The header name will have been normalized per HTTP standards defined in [RFC2616 Section 4.2](https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2) regardless of what is being sent by a client.
|
1872
|
+
|
1873
|
+
### Response
|
1874
|
+
|
1812
1875
|
You can set a response header with `header` inside an API.
|
1813
1876
|
|
1814
1877
|
```ruby
|
1815
1878
|
header 'X-Robots-Tag', 'noindex'
|
1816
1879
|
```
|
1817
1880
|
|
1818
|
-
When raising `error!`, pass additional headers as arguments.
|
1881
|
+
When raising `error!`, pass additional headers as arguments. Additional headers will be merged with headers set before `error!` call.
|
1819
1882
|
|
1820
1883
|
```ruby
|
1821
1884
|
error! 'Unauthorized', 401, 'X-Error-Detail' => 'Invalid token.'
|
@@ -2155,6 +2218,12 @@ instead of a message.
|
|
2155
2218
|
error!({ error: 'unexpected error', detail: 'missing widget' }, 500)
|
2156
2219
|
```
|
2157
2220
|
|
2221
|
+
You can set additional headers for the response. They will be merged with headers set before `error!` call.
|
2222
|
+
|
2223
|
+
```ruby
|
2224
|
+
error!('Something went wrong', 500, 'X-Error-Detail' => 'Invalid token.')
|
2225
|
+
```
|
2226
|
+
|
2158
2227
|
You can present documented errors with a Grape entity using the the [grape-entity](https://github.com/ruby-grape/grape-entity) gem.
|
2159
2228
|
|
2160
2229
|
```ruby
|
@@ -3089,19 +3158,22 @@ class ApiLogger < Grape::Middleware::Base
|
|
3089
3158
|
end
|
3090
3159
|
```
|
3091
3160
|
|
3092
|
-
## Before and
|
3161
|
+
## Before, After and Finally
|
3093
3162
|
|
3094
3163
|
Blocks can be executed before or after every API call, using `before`, `after`,
|
3095
3164
|
`before_validation` and `after_validation`.
|
3165
|
+
If the API fails the `after` call will not be trigered, if you need code to execute for sure
|
3166
|
+
use the `finally`.
|
3096
3167
|
|
3097
3168
|
Before and after callbacks execute in the following order:
|
3098
3169
|
|
3099
3170
|
1. `before`
|
3100
3171
|
2. `before_validation`
|
3101
3172
|
3. _validations_
|
3102
|
-
4. `after_validation`
|
3103
|
-
5. _the API call_
|
3104
|
-
6. `after`
|
3173
|
+
4. `after_validation` (upon successful validation)
|
3174
|
+
5. _the API call_ (upon successful validation)
|
3175
|
+
6. `after` (upon successful validation and API call)
|
3176
|
+
7. `finally` (always)
|
3105
3177
|
|
3106
3178
|
Steps 4, 5 and 6 only happen if validation succeeds.
|
3107
3179
|
|
@@ -3121,6 +3193,14 @@ before do
|
|
3121
3193
|
end
|
3122
3194
|
```
|
3123
3195
|
|
3196
|
+
You can ensure a block of code runs after every request (including failures) with `finally`:
|
3197
|
+
|
3198
|
+
```ruby
|
3199
|
+
finally do
|
3200
|
+
# this code will run after every request (successful or failed)
|
3201
|
+
end
|
3202
|
+
```
|
3203
|
+
|
3124
3204
|
**Namespaces**
|
3125
3205
|
|
3126
3206
|
Callbacks apply to each API call within and below the current namespace:
|
@@ -3645,4 +3725,4 @@ MIT License. See LICENSE for details.
|
|
3645
3725
|
|
3646
3726
|
## Copyright
|
3647
3727
|
|
3648
|
-
Copyright (c) 2010-
|
3728
|
+
Copyright (c) 2010-2019 Michael Bleigh, Intridea Inc. and Contributors.
|
data/UPGRADING.md
CHANGED
@@ -1,6 +1,38 @@
|
|
1
1
|
Upgrading Grape
|
2
2
|
===============
|
3
3
|
|
4
|
+
### Upgrading to >= 1.2.4
|
5
|
+
|
6
|
+
#### Headers in `error!` call
|
7
|
+
|
8
|
+
Headers in `error!` will be merged with `headers` hash. If any header need to be cleared on `error!` call, make sure to move it to the `after` block.
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
class SampleApi < Grape::API
|
12
|
+
before do
|
13
|
+
header 'X-Before-Header', 'before_call'
|
14
|
+
end
|
15
|
+
|
16
|
+
get 'ping' do
|
17
|
+
header 'X-App-Header', 'on_call'
|
18
|
+
error! :pong, 400, 'X-Error-Details' => 'Invalid token'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
```
|
22
|
+
**Former behaviour**
|
23
|
+
```ruby
|
24
|
+
response.headers['X-Before-Header'] # => nil
|
25
|
+
response.headers['X-App-Header'] # => nil
|
26
|
+
response.headers['X-Error-Details'] # => Invalid token
|
27
|
+
```
|
28
|
+
|
29
|
+
**Current behaviour**
|
30
|
+
```ruby
|
31
|
+
response.headers['X-Before-Header'] # => 'before_call'
|
32
|
+
response.headers['X-App-Header'] # => 'on_call'
|
33
|
+
response.headers['X-Error-Details'] # => Invalid token
|
34
|
+
```
|
35
|
+
|
4
36
|
### Upgrading to >= 1.2.1
|
5
37
|
|
6
38
|
#### Obtaining the name of a mounted class
|