Skip to content

Conversation

@ericproulx
Copy link
Contributor

@ericproulx ericproulx commented Oct 20, 2024

Fix #2171

This PR also introduce the function api_format which can be used in route. Instead of env['api.format'], we can now user api_format :format. Seems better than exposing internal api.format.

I've also took the opportunity to set HTTP_VERSION in Grape::Http::Headers and use it. Finally, instead of using [] || pattern for a Hash, I've changed it to .fetch() {} which seems a bit faster.

irb(main):002* Benchmark.ips do |x|
irb(main):003*   x.report("fetch") { {}.fetch(:non_existance, true) }
irb(main):004*    x.report("[] ||") { {}[:non_existance] || true }
irb(main):005> end; nil
ruby 3.3.4 (2024-07-09 revision be1089c8ec) [arm64-darwin23]
Warming up --------------------------------------
               fetch     1.511M i/100ms
               [] ||     1.446M i/100ms
Calculating -------------------------------------
               fetch     15.149M (± 3.1%) i/s   (66.01 ns/i) -     77.071M in   5.093208s
               [] ||     14.418M (± 1.1%) i/s   (69.36 ns/i) -     72.310M in   5.015870s
=> nil

fetch_formatter will look api.format first
Use fetch {} instead of [] ||
Update spec
Add HTTP_VERSION in Grape::Http::Headers
Update README
@ericproulx ericproulx marked this pull request as ready for review October 20, 2024 13:28
@ericproulx ericproulx requested a review from dblock October 20, 2024 13:28
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some text nits. Thanks.

@ericproulx ericproulx requested a review from dblock October 20, 2024 14:02
@dblock dblock merged commit f4e2af5 into ruby-grape:master Oct 20, 2024
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

env['api.format'] does not override formatter set by content-type

2 participants