From 0318928468488d81b17c55a42575f72165f28ad4 Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Sun, 22 Nov 2026 08:59:46 -0500 Subject: [PATCH] Document link properties, including HAL profile Link#_profile and the other HAL link properties have been supported since 2013 but were undocumented. Document them in the README, add a title and profile to the Oxford demo's places link, and test reading and fetching the profile. Co-Authored-By: Claude Claude-Session: https://claude.ai/code/session_011Gr21htyJfr8XZGHBcPwkW --- CHANGELOG.md | 1 + README.md | 18 ++++++++++++++++++ examples/oxford/app.rb | 2 +- examples/oxford/client.rb | 1 + test/oxford_example_test.rb | 11 +++++++++++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe6c1a0..cdbadf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * [#334](https://github.com/codegram/hyperclient/pull/334): Added `Link#_query` to send query parameters that a link doesn't declare - [@dblock](https://github.com/dblock). * [#336](https://github.com/codegram/hyperclient/pull/336): Fixed `SystemStackError` when iterating a link whose resource links back to itself under the same name, raising `Hyperclient::SelfReferencingLinkError` instead - [@dblock](https://github.com/dblock). * [#337](https://github.com/codegram/hyperclient/pull/337): Updated danger-pr-comment to 0.3.0 and stopped posting empty Danger reports - [@dblock](https://github.com/dblock). +* [#338](https://github.com/codegram/hyperclient/pull/338): Documented link properties, including HAL `profile` via `Link#_profile` - [@dblock](https://github.com/dblock). * Your contribution here. ### 2.1.0 (2026/10/14) diff --git a/README.md b/README.md index 9c169fc..f360510 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Hyperclient is a Hypermedia API client written in Ruby. It fully supports [JSON - [Links and Embedded Resources](#links-and-embedded-resources) - [Templated Links](#templated-links) - [Query Parameters](#query-parameters) + - [Link Properties](#link-properties) - [Curies](#curies) - [Attributes](#attributes) - [HTTP](#http) @@ -168,6 +169,23 @@ api._links.place._expand(id: 'oxpoints:23232339')._query(fields: 'name')._get # Array values are sent as repeated parameters, and parameters with `nil` values are dropped. +## Link Properties + +HAL links can carry optional [properties](https://datatracker.ietf.org/doc/html/draft-kelly-json-hal-11#section-5) besides `href` and `templated`. Hyperclient exposes them as `_type`, `_deprecation`, `_name`, `_profile`, `_title`, and `_hreflang`, each returning `nil` when the property is absent. The local demo gives its `places` link a `title` and a `profile`. + +```ruby +puts api._links.places._title # => Oxford places +puts api._links.places._profile # => /docs/places +``` + +A [`profile`](https://datatracker.ietf.org/doc/html/rfc6906) is a URI that documents the semantics of the target resource, beyond what the media type describes. Hyperclient returns it as-is and doesn't follow it, since a profile isn't necessarily a HAL resource. Fetch it with the client's Faraday connection if you need it. + +```ruby +puts api.connection.get(api._links.places._profile).body['description'] # => Archived Oxford place facts in a local HAL collection. +``` + +A link with a `deprecation` property will be removed in the future, and `_deprecation` returns a URL with more information about the deprecation. + ## Curies Curies provide compact names for relation documentation. The local demo adds an `oxford` CURIE and an `oxford:places` relation. diff --git a/examples/oxford/app.rb b/examples/oxford/app.rb index 27f128b..f0cfd13 100644 --- a/examples/oxford/app.rb +++ b/examples/oxford/app.rb @@ -24,7 +24,7 @@ def representation(path) [200, { '_links' => { 'self' => { 'href' => '/' }, - 'places' => { 'href' => '/places/' }, + 'places' => { 'href' => '/places/', 'title' => 'Oxford places', 'profile' => '/docs/places' }, 'place' => { 'href' => '/places/{id}', 'templated' => true }, 'curies' => [{ 'name' => 'oxford', 'href' => '/docs/{rel}', 'templated' => true }], 'oxford:places' => { 'href' => '/places/' } diff --git a/examples/oxford/client.rb b/examples/oxford/client.rb index e5da46b..bb2eace 100644 --- a/examples/oxford/client.rb +++ b/examples/oxford/client.rb @@ -11,3 +11,4 @@ puts "Archived #{file.type} URL (not fetched): #{file.url}" end puts "CURIE: #{api._links._curies['oxford'].expand('places')}" +puts "Places profile: #{api._links.places._profile}" diff --git a/test/oxford_example_test.rb b/test/oxford_example_test.rb index 8ab1693..6488e36 100644 --- a/test/oxford_example_test.rb +++ b/test/oxford_example_test.rb @@ -28,6 +28,7 @@ _(output).must_include 'Followed primary_place: Balliol College' _(output).must_include 'Archived depiction URL (not fetched):' _(output).must_include 'CURIE: /docs/places' + _(output).must_include 'Places profile: /docs/places' end it 'supports explicit navigation, hash attributes, and embedded resources' do @@ -40,6 +41,16 @@ _(api._links['oxford:places']._embedded.places.first.name).must_equal 'Balliol College' end + it 'exposes link properties, including a profile that can be fetched' do + api = Hyperclient.new('http://127.0.0.1:9292/') + places = api._links.places + + _(places._title).must_equal 'Oxford places' + _(places._profile).must_equal '/docs/places' + _(places._deprecation).must_be_nil + _(api.connection.get(places._profile).body['description']).must_include 'Oxford place facts' + end + it 'serves HAL, rejects writes, and reports missing resources' do status, headers, = app.call('REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/')