|
1 | 1 | Upgrading Grape
|
2 | 2 | ===============
|
3 | 3 |
|
| 4 | +### Upgrading to >= 2.4.0 |
| 5 | + |
| 6 | +#### Grape::Http::Headers, Grape::Util::Lazy::Object |
| 7 | + |
| 8 | +Both have been removed. See [2554](https://github.com/ruby-grape/grape/pull/2554). |
| 9 | +Here are the notable changes: |
| 10 | + |
| 11 | +- Constants like `HTTP_ACCEPT` have been replaced by their literal value. |
| 12 | +- `SUPPORTED_METHODS` has been moved to `Grape` module. |
| 13 | +- `HTTP_HEADERS` has been moved to `Grape::Request` and renamed `KNOWN_HEADERS`. The last has been refreshed with new headers, and it's not lazy anymore. |
| 14 | +- `SUPPORTED_METHODS_WITHOUT_OPTIONS` and `find_supported_method` have been removed. |
| 15 | + |
| 16 | +### Grape::Middleware::Base |
| 17 | + |
| 18 | +- Constant `TEXT_HTML` has been removed in favor of using literal string 'text/html'. |
| 19 | +- `rack_request` and `query_params` have been added. Feel free to call these in your middlewares. |
| 20 | + |
4 | 21 | #### Params Builder
|
5 | 22 |
|
6 | 23 | - Passing a class to `build_with` or `Grape.config.param_builder` has been deprecated in favor of a symbolized short_name. See `SHORTNAME_LOOKUP` in [params_builder](lib/grape/params_builder.rb).
|
7 | 24 | - Including Grape's extensions like `Grape::Extensions::Hashie::Mash::ParamBuilder` has been deprecated in favor of using `build_with` at the route level.
|
8 | 25 |
|
9 |
| -### Upgrading to >= 2.4.0 |
| 26 | +#### Accept Header Negotiation Harmonized |
| 27 | + |
| 28 | +[Accept](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Accept) header is now fully interpreted through `Rack::Utils.best_q_match` which is following [RFC2616 14.1](https://datatracker.ietf.org/doc/html/rfc2616#section-14.1). Since [Grape 2.1.0](https://github.com/ruby-grape/grape/blob/master/CHANGELOG.md#210-20240615), the [header versioning strategy](https://github.com/ruby-grape/grape?tab=readme-ov-file#header) was adhering to it, but `Grape::Middleware::Formatter` never did. |
| 29 | + |
| 30 | +Your API might act differently since it will strictly follow the [RFC2616 14.1](https://datatracker.ietf.org/doc/html/rfc2616#section-14.1) when interpreting the `Accept` header. Here are the differences: |
| 31 | + |
| 32 | +###### Invalid or missing quality ranking |
| 33 | +The following used to yield `application/xml` and now will yield `application/json` as the preferred media type: |
| 34 | +- `application/json;q=invalid,application/xml;q=0.5` |
| 35 | +- `application/json,application/xml;q=1.0` |
| 36 | + |
| 37 | +For the invalid case, the value `invalid` was automatically `to_f` and `invalid.to_f` equals `0.0`. Now, since it doesn't match [Rack's regex](https://github.com/rack/rack/blob/3-1-stable/lib/rack/utils.rb#L138), its interpreted as non provided and its quality ranking equals 1.0. |
| 38 | + |
| 39 | +For the non provided case, 1.0 was automatically assigned and in a case of multiple best matches, the first was returned based on Ruby's sort_by `quality`. Now, 1.0 is still assigned and the last is returned in case of multiple best matches. See [Rack's implementation](https://github.com/rack/rack/blob/e8f47608668d507e0f231a932fa37c9ca551c0a5/lib/rack/utils.rb#L167) of the RFC. |
| 40 | + |
| 41 | +###### Considering the closest generic when vendor tree |
| 42 | +Excluding the [header versioning strategy](https://github.com/ruby-grape/grape?tab=readme-ov-file#header), whenever a media type with the [vendor tree](https://datatracker.ietf.org/doc/html/rfc6838#section-3.2) leading facet `vnd.` like `application/vnd.api+json` was provided, Grape would also consider its closest generic when negotiating. In that case, `application/json` was added to the negotiation. Now, it will just consider the provided media types without considering any closest generics, and you'll need to [register](https://github.com/ruby-grape/grape?tab=readme-ov-file#api-formats) it. |
| 43 | +You can find the official vendor tree registrations on [IANA](https://www.iana.org/assignments/media-types/media-types.xhtml) |
10 | 44 |
|
11 | 45 | #### Custom Validators
|
12 | 46 |
|
|
0 commit comments