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

Configurable JSON encoders and decoders #1539

Merged
merged 8 commits into from
Dec 20, 2023

Conversation

ne006
Copy link
Contributor

@ne006 ne006 commented Dec 19, 2023

Moves lostisland/faraday_middleware/#286

By default Faraday::Request::Json and Faraday::Response::Json use json to encode/decode JSON data, although there are gems like oj which do the job faster than Ruby's built-in json.

This implementation allows to pass encoder option to Faraday::Request::Json and decoder option to pass in parser_options to Faraday::Response::Json

require 'oj'

Faraday.new do |f|
  f.request :json, encoder: Oj
  f.response :json, parser_options: { decoder: Oj }
end

@ne006 ne006 marked this pull request as ready for review December 19, 2023 07:58
@ne006 ne006 changed the title Feature/json encoders and decoders Configurable JSON encoders and decoders Dec 19, 2023
Copy link
Member

@iMacTia iMacTia left a comment

Choose a reason for hiding this comment

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

Thank you for moving this contribution 🙏 !
I've left some minor comments to be addressed, but overall this looks good, well test-covered and documented 💯

lib/faraday/response/json.rb Outdated Show resolved Hide resolved
lib/faraday/request/json.rb Outdated Show resolved Hide resolved
lib/faraday/request/json.rb Outdated Show resolved Hide resolved
docs/middleware/included/json.md Outdated Show resolved Hide resolved
Copy link
Member

@iMacTia iMacTia left a comment

Choose a reason for hiding this comment

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

Few more minor changes, sorry for being picky 🙏!

lib/faraday/response/json.rb Outdated Show resolved Hide resolved
docs/middleware/included/json.md Outdated Show resolved Hide resolved
docs/middleware/included/json.md Outdated Show resolved Hide resolved
Copy link
Member

@iMacTia iMacTia left a comment

Choose a reason for hiding this comment

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

Thank you for patiently addressing all my comments, LGTM 🎉 !

@iMacTia iMacTia merged commit 1e81e2c into lostisland:main Dec 20, 2023
8 checks passed
@victorhazbun
Copy link

Take, a digital 🍺 !

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.

3 participants