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

Introduce Middleware DEFAULT_OPTIONS with Application and Instance Configurability #1572

Merged

Conversation

ryan-mcneil
Copy link
Contributor

@ryan-mcneil ryan-mcneil commented Jun 27, 2024

Description

This PR introduces a new feature to Faraday::Middleware: Default Options. While the concept of DEFAULT_OPTIONS isn't fundamentally new to Faraday, this PR provides some building blocks to introduce Default Options, and the ability to override them at the application level. While it has only been implemented in the RaiseError class, it can easily be added to other Faraday::Middleware classes for which there's a need.

The suggestion was first mentioned here with some conversation and ideation afterwards. As our team did have a need for this functionality (i.e. setting a different default for :include_request), I created a little monkeypatch in our repo, and figured I'd submit a [much more thought out] addition to Faraday itself.

My addition to the documentation (please let me know if you would like this elsewhere!) mostly sums up the general idea and how a user would implement it.

Addresses comment here

Additional Notes

The additional "feature" that I did not include in the documentation is that this implementation allows for DEFAULT_OPTIONS to be set at the FARADAY::MIDDLEWARE level, that would be propagated to child classes. Leaving it blank for now allows for the feature to work as intended, but could open it up for additional configuration in future iterations of the gem. I'd love to hear your thoughts here.

This is my first time contributing to a widely used gem, so be gentle 😆

@ryan-mcneil ryan-mcneil marked this pull request as ready for review July 3, 2024 20:56
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.

Hi @ryan-mcneil, thank you for the thorough PR (complete with extensive documentation, much appreciated 🙏) and apologies if it took me longer than expected to review.

This looks really great and implements pretty well what I had in mind and described in the comments you linked to.
I requested a couple changes but this looks like a really solid start 💪

docs/middleware/index.md Outdated Show resolved Hide resolved
lib/faraday/middleware.rb Outdated Show resolved Hide resolved
lib/faraday/middleware.rb Show resolved Hide resolved
@iMacTia iMacTia mentioned this pull request Jul 5, 2024
@ryan-mcneil
Copy link
Contributor Author

@iMacTia good catch on the typo 🤦 , and thanks for the feedback!

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.

Looking great, congrats on your first Faraday contribution 🙌
This was very well executed 💯

@iMacTia iMacTia merged commit d83a281 into lostisland:main Jul 5, 2024
7 checks passed
@iMacTia
Copy link
Member

iMacTia commented Jul 5, 2024

Release note: I'll be away most of the weekend so I'll cut a release on Monday if that's OK as I would hate to be unavailable in case anything goes wrong

@ryan-mcneil
Copy link
Contributor Author

Shoutout to @ericboehs for the assist!

Thanks @iMacTia! Looking forward to it!

@iMacTia
Copy link
Member

iMacTia commented Jul 8, 2024

This has just been released in v2.10.0 🚀

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.

2 participants