lostisland / faraday

Simple, but flexible HTTP client library, with support for multiple backends.
https://lostisland.github.io/faraday
MIT License
5.73k stars 976 forks source link

Introduce Middleware DEFAULT_OPTIONS with Application and Instance Configurability #1572

Closed ryan-mcneil closed 3 months ago

ryan-mcneil commented 3 months ago

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 commented 3 months ago

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

iMacTia commented 3 months ago

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 commented 3 months ago

Shoutout to @ericboehs for the assist!

Thanks @iMacTia! Looking forward to it!

iMacTia commented 2 months ago

This has just been released in v2.10.0 🚀