You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 276b7d1
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@
2
2
3
3
### 2.0.1 (Next)
4
4
5
+
*[#328](https://github.com/codegram/hyperclient/pull/328): Replaced the retired Splines demo with a local read-only Oxford HAL example using archived place facts - [@dblock](https://github.com/dblock).
5
6
*[#298](https://github.com/codegram/hyperclient/pull/300): Upgraded RuboCop to 1.80.2 - [@dblock](https://github.com/dblock).
6
7
*[#298](https://github.com/codegram/hyperclient/pull/298): Upgraded RuboCop to 1.63.5 - [@dblock](https://github.com/dblock).
7
8
*[#319](https://github.com/codegram/hyperclient/pull/319): Fixed `Resource#to_h` returning `nil` instead of the same result as `#to_hash` - [@dblock](https://github.com/dblock).
Copy file name to clipboardExpand all lines: README.md
+41-39Lines changed: 41 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,7 +24,7 @@ Hyperclient is a Hypermedia API client written in Ruby. It fully supports [JSON
24
24
25
25
# Usage
26
26
27
-
The examples in this README use the [Splines Demo API](https://github.com/ruby-grape/grape-with-roar) running [here](https://grape-with-roar.herokuapp.com/api). Use version 1.x with Faraday 1.x, and version 2.x with Faraday 2.x. If you're upgrading from a previous version, please make sure to read [UPGRADING](UPGRADING.md).
27
+
The examples in this README use the [local Oxford HAL demo](examples/oxford/README.md), based on historical Oxford place facts. Start it with `bundle exec ruby examples/oxford/server.rb`, then run `bundle exec ruby -Ilib examples/oxford/client.rb` in another terminal. No external service is needed. Use version 1.x with Faraday 1.x, and version 2.x with Faraday 2.x. If you're upgrading from a previous version, please make sure to read [UPGRADING](UPGRADING.md).
28
28
29
29
Hyperclient is tested with JSON 2.x on Ruby 2.7, both JSON 2.x and 3.x on Ruby 3.2, and JSON 3.x on newer Rubies. JSON 3.x requires a Faraday release with keyword parser options support (2.14.4+).
30
30
@@ -35,21 +35,21 @@ Create an API client.
35
35
```ruby
36
36
require'hyperclient'
37
37
38
-
api =Hyperclient.new('https://grape-with-roar.herokuapp.com/api')
38
+
api =Hyperclient.new('http://127.0.0.1:9292/')
39
39
```
40
40
41
41
By default, Hyperclient adds `application/hal+json` as `Content-Type` and `Accept` headers. It will also send requests as JSON and parse JSON responses. Specify additional headers or authentication if necessary.
42
42
43
43
```ruby
44
-
api =Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
44
+
api =Hyperclient.new('http://127.0.0.1:9292/') do |client|
45
45
client.headers['Access-Token'] ='token'
46
46
end
47
47
```
48
48
49
49
Hyperclient constructs a connection using typical [Faraday](http://github.com/lostisland/faraday) middleware for handling JSON requests and responses. You can specify additional Faraday middleware if necessary.
50
50
51
51
```ruby
52
-
api =Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
52
+
api =Hyperclient.new('http://127.0.0.1:9292/') do |client|
53
53
client.connection do |conn|
54
54
conn.use Faraday::Request::Instrumentation
55
55
end
@@ -59,7 +59,7 @@ end
59
59
You can pass options to the Faraday connection block in the `connection` block:
60
60
61
61
```ruby
62
-
api =Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
62
+
api =Hyperclient.new('http://127.0.0.1:9292/') do |client|
63
63
client.connection(ssl: { verify:false }) do |conn|
64
64
conn.use Faraday::Request::Instrumentation
65
65
end
@@ -69,15 +69,15 @@ end
69
69
Or when using the default connection configuration you can use `faraday_options`:
70
70
71
71
```ruby
72
-
api =Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
72
+
api =Hyperclient.new('http://127.0.0.1:9292/') do |client|
You can build a new Faraday connection block without inheriting default middleware by specifying `default: false` in the `connection` block.
78
78
79
79
```ruby
80
-
api =Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
80
+
api =Hyperclient.new('http://127.0.0.1:9292/') do |client|
81
81
client.connection(default:false) do |conn|
82
82
conn.request :json
83
83
conn.response :json, content_type:/\bjson$/
@@ -93,7 +93,7 @@ You can modify headers or specify authentication after a connection has been cre
93
93
```ruby
94
94
require'faraday/digestauth'
95
95
96
-
api =Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client|
96
+
api =Hyperclient.new('http://127.0.0.1:9292/') do |client|
97
97
client.connection(default:false) do |conn|
98
98
conn.request :digest, 'username', 'password'
99
99
conn.request :json
@@ -106,7 +106,7 @@ end
106
106
You can access the Faraday connection directly after it has been created and add middleware to it. As an example, you could use the [faraday-http-cache-middleware](https://github.com/plataformatec/faraday-http-cache).
107
107
108
108
```ruby
109
-
api =Hyperclient.new('https://grape-with-roar.herokuapp.com/api')
Hyperclient will fetch and discover the resources from your API and automatically paginate when possible.
116
116
117
117
```ruby
118
-
api.splines.each do |spline|
119
-
puts"A spline with ID #{spline.uuid}."
118
+
api.places.each do |place|
119
+
puts"#{place.name} has ID #{place.id}."
120
120
end
121
121
```
122
122
123
123
Other methods, including `[]` and `fetch` are also available
124
124
125
125
```ruby
126
-
api.splines.each do |spline|
127
-
puts"A spline with ID #{spline[:uuid]}."
128
-
puts"Maybe with reticulated: #{spline.fetch(:reticulated, '-- no reticulated')}"
126
+
api.places.each do |place|
127
+
puts"A place with ID #{place[:id]}."
128
+
puts"Address: #{place.fetch(:address, '-- no address')}"
129
129
end
130
130
```
131
131
132
132
## Links and Embedded Resources
133
133
134
-
The splines example above followed a link called "splines". While you can, you do not need to specify the HAL navigational structure, including links or embedded resources. Hyperclient will resolve these for you. If you prefer, you can explicitly navigate the link structure via `_links`. In the following example the "splines" link leads to a collection of embedded splines. Invoking `api.splines` is equivalent to `api._links.splines._embedded.splines`.
134
+
The example above follows the `places`link to a collection of embedded places. Hyperclient resolves links and embedded resources automatically. You can also navigate explicitly:
135
135
136
136
```ruby
137
-
api._links.splines
137
+
api._links.places._embedded.places.each do |place|
138
+
puts place.name
139
+
end
140
+
141
+
place = api.place(id:'oxpoints:23232339')
142
+
puts place.primary_place.name # follows a relative link to Balliol College
143
+
puts place._embedded.files.first.url # reads embedded metadata, without fetching the image
138
144
```
139
145
140
146
## Templated Links
141
147
142
-
Templated links require variables to be expanded. For example, the demo API has a link called "spline" that requires a spline "uuid".
148
+
Templated links require variables to be expanded. The local demo adds a `place`link that accepts an Oxford place ID.
143
149
144
150
```ruby
145
-
spline= api.spline(uuid:'uuid')
146
-
puts"Spline #{spline.uuid} is #{spline.reticulated ?'reticulated' : 'not reticulated'}."
151
+
place= api.place(id:'oxpoints:23232339')
152
+
putsplace.name # => Balliol College
147
153
```
148
154
149
-
Invoking `api.spline(uuid: 'uuid').reticulated` is equivalent to `api._links.spline._expand(uuid: 'uuid')._resource._attributes.reticulated`.
155
+
Invoking `api.place(id: 'oxpoints:23232339').name` is equivalent to `api._links.place._expand(id: 'oxpoints:23232339')._resource._attributes.name`.
150
156
151
157
The client is responsible for supplying all the necessary parameters. Templated links don't do any strict parameter name checking and don't support required vs. optional parameters. Parameters not declared by the API will be dropped and will not have any effect when passed to `_expand`.
152
158
153
159
## Curies
154
160
155
-
Curies are a suggested means by which to link documentation of a given resource. For example, the demo API contains very long links to images that use an "images" curie.
161
+
Curies provide compact names for relation documentation. The local demo adds an `oxford` CURIE and an `oxford:places` relation.
For a complete example refer to [this Splines Demo API test](https://github.com/ruby-grape/grape-with-roar/blob/master/spec/api/splines_endpoint_with_hyperclient_spec.rb).
244
+
For a complete offline example, see the [Oxford demo smoke test](test/oxford_example_test.rb).
This read-only demo uses a small selection of public place facts from Oxford's retired mobile API. It runs entirely on localhost; neither Oxford nor the Internet Archive is contacted when running the example. The information is historical, not a current directory.
4
+
5
+
From the repository root, install dependencies and start the server:
6
+
7
+
```sh
8
+
bundle install
9
+
bundle exec ruby examples/oxford/server.rb
10
+
```
11
+
12
+
In a second terminal:
13
+
14
+
```sh
15
+
bundle exec ruby -Ilib examples/oxford/client.rb
16
+
```
17
+
18
+
The server binds only to `127.0.0.1:9292`. Set `PORT` on the server and `OXFORD_URL` on the client to use another port. Stop the server with Ctrl-C.
19
+
20
+
The client demonstrates collection traversal, attributes, a templated place link, following `primary_place`, embedded file metadata, and CURIE expansion. It prints image URLs without downloading images. Unknown paths return 404; writes return 405.
21
+
22
+
## Provenance and Adaptations
23
+
24
+
The factual fields and original place path in `places.json` were transcribed from [Balliol College's archived response, September 10, 2020](https://web.archive.org/web/20200910141343id_/https://api.m.ox.ac.uk/places/oxpoints:23232339). The record retains the original ID, name, address, coordinates, self/primary-place paths, and one image URL. No image or descriptive prose is redistributed.
25
+
26
+
The [archived API root, July 12, 2024](https://web.archive.org/web/20240712050404id_/http://api.m.ox.ac.uk/) demonstrates the original HAL-style links. See also [Moxie's OxPoints importer documentation](https://moxie.readthedocs.io/en/latest/places/oxpoints.html).
27
+
28
+
## Data License
29
+
30
+
The underlying OxPoints place data is dedicated to the public domain under [CC0](https://creativecommons.org/publicdomain/zero/1.0/). Oxford's own presentation, [*OxPoints and data.ox.ac.uk*, Alexander Dutton, InfoDev, OUCS (2011)](https://old.ictf.ox.ac.uk/conference/2011/presentations/wks11_oxpoints_dataox.pdf), identifies names, coordinates, addresses, and identifiers as OxPoints data (slides 2-5) and explicitly states "Public domain (CC0; no attribution required)" (slide 8). The place facts in `places.json` come from this dataset via the archived mobile API response cited above; the HAL wrappers and local links are demo adaptations.
31
+
32
+
This is not a license claim for full archived API responses or photographs. The depiction URL is retained only as a reference to an external image; the image itself is not included, fetched, or covered by this notice. Newly authored server code and documentation are under this project's license. Moxie's Apache-2.0 code license is separate from the OxPoints data license.
33
+
34
+
The root, collection wrapper, templated `place` link, `oxford` CURIE, and local relation documentation are demo additions, not a reconstruction of the original service. Responses use `application/hal+json`; the archived service returned `application/json`. Relative place links retain their original paths and resolve locally. Unavailable child links, images, and unrelated API endpoints are not mirrored.
The tests exercise the same app and client using local HTTP stubs, without requiring a running server or external network access. They are also included in `bundle exec rake test`.
0 commit comments