A Ruby gem client for discovering and fetching well-known URLs (RFC 8615) from any domain. Includes the full IANA well-known URI registry.
- Pure Ruby - Works with any Ruby framework or plain scripts
- Client - Fetch
/.well-known/{suffix}from any domain - Registry - Full IANA well-known URI registry (96 entries)
- Lookup - Check if a URI suffix is IANA-registered
Add this line to your application's Gemfile:
gem 'well_known'And then execute:
bundle installOr install it yourself as:
gem install well_knownFetch well-known URLs from any domain:
require 'well_known'
client = WellKnown::Client.new
# Fetch nodeinfo
response = client.fetch 'mastodon.social', 'nodeinfo'
puts response.status # => 200
puts response.body # => '{"links":[...]}'
puts response.content_type # => 'application/json'
# Fetch host-meta
response = client.fetch 'mastodon.social', 'host-meta'
puts response.content_type # => 'application/xrd+xml'
# Fetch security.txt
response = client.fetch 'example.com', 'security.txt'
puts response.body # => 'Contact: security@example.com'client = WellKnown::Client.new
client.url_for 'mastodon.social', 'nodeinfo'
# => 'https://mastodon.social/.well-known/nodeinfo'
client.url_for 'example.com', 'webfinger'
# => 'https://example.com/.well-known/webfinger'# Custom timeout (default: 10 seconds)
client = WellKnown::Client.new timeout: 5
# Disable redirect following (default: true)
client = WellKnown::Client.new follow_redirects: falseclient = WellKnown.client
response = client.fetch 'example.com', 'nodeinfo'Check the IANA well-known URI registry:
require 'well_known'
# Check if a suffix is registered
WellKnown::Registry.registered? 'nodeinfo' # => true
WellKnown::Registry.registered? 'webfinger' # => true
WellKnown::Registry.registered? 'made-up' # => false
# Get details for a registered suffix
WellKnown::Registry.find 'nodeinfo'
# => { change_controller: 'NodeInfo Developer Community', reference: 'NodeInfo Diaspora' }
WellKnown::Registry.find 'webfinger'
# => { change_controller: 'IETF', reference: 'RFC 7033' }
# List all registered suffixes
WellKnown::Registry.suffixes
# => ['acme-challenge', 'agent-card.json', 'amphtml', ...]
# Get the full registry
WellKnown::Registry.entries
# => { 'acme-challenge' => { ... }, 'agent-card.json' => { ... }, ... }The WellKnown::Response object wraps the HTTP response:
response = client.fetch 'example.com', 'nodeinfo'
response.body # => String - the response body
response.status # => Integer - HTTP status code (e.g., 200)
response.content_type # => String - MIME type (e.g., 'application/json')
response.headers # => Hash - all response headers
response.success? # => Boolean - true if status is 2xxbegin
response = client.fetch 'example.com', 'nodeinfo'
rescue WellKnown::FetchError => e
puts "Could not fetch: #{e.message}"
rescue WellKnown::Error => e
puts "WellKnown error: #{e.message}"
endAfter checking out the repo, run bin/setup to install dependencies.
Then, run rake spec to run the tests.
You can also run bin/console for an interactive prompt that will allow you to experiment.
bundle exec rspecbundle exec rubocopbundle exec rakeBug reports and pull requests are welcome on GitHub at the https://github.com/xoengineering/well_known repo.
The gem is available as open source under the terms of the MIT License.