Faraday Sunset
Watch out for HTTP responses declaring their end of life, using the Sunset header to signal deprecation (and eventual removal) of an endpoint.
Sunset is an in-development HTTP response header. Check out GitHub for issues and discussion around it's development.
This specification defines the Sunset HTTP response header field, which indicates that a URI is likely to become unresponsive at a specified point in the future.
The header we're sniffing for looks a little like this:
Sunset: Sat, 31 Dec 2018 23:59:59 GMT
So long as the server being called is inserting a Sunset
header to the response with a HTTP date, this client-side code will do stuff.
Usage
Add gem to Gemfile:
gem 'faraday-sunset'
Enabling Sunset detection is as simple as referencing the middleware in your Faraday connection block:
connection = Faraday.new(url: '...') do |conn|
conn.response :sunset, active_support: true
# or
conn.response :sunset, logger: Rails.logger
# or
conn.response :sunset, rollbar: true
# or combine:
conn.response :sunset, rollbar: :auto, active_support: true, logger: Rails.logger
end
For logger
, You can pass in any object that acts a bit like a Rack logger, Rails logger, or anything with a warn
method that takes a string.
You can configure ActiveSupport::Deprecation
to warn in 3 ways:
-
true
- throw warnings on sunsetted endpoints, and throw an error if active-support is missing from the project -
false
- ignore active-support -
:auto
- throw warnings on sunsetted endpoints, and ignore if active-support is missing from the project
You can [configure Rollbar
][rollbar] in 3 ways:
-
true
- throw warnings on sunsetted endpoints, and throw an error if active-support is missing from the project -
false
- ignore rollbar -
:auto
- throw warnings on sunsetted endpoints, and ignore if Rollbar is missing from the project
Requirements
- Ruby: v2.2 - v2.5
- Faraday: v0.9 - v0.14
Related Projects
- rails-sunset - Mark your endpoints as deprecated the Railsy way
- guzzle-sunset - Sniff for deprecations with popular PHP client Guzzle
TODO
- Surface
Link
with rel=sunset as per Sunset RFC draft 04?
Testing
To run tests and modify locally, you'll want to bundle install
in this directory.
bundle exec appraisal rspec
Contributing
Bug reports and pull requests are welcome on GitHub at wework/faraday-sunset. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.