Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fetch_formatter api_format #2506

Merged
merged 4 commits into from
Oct 20, 2024

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
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.

UPGRADING.md Outdated Show resolved Hide resolved
UPGRADING.md Outdated Show resolved Hide resolved
@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