Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/oxford/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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/' }
Expand Down
1 change: 1 addition & 0 deletions examples/oxford/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
11 changes: 11 additions & 0 deletions test/oxford_example_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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' => '/')

Expand Down
Loading