From f2c296427f5d0d92deb577c2ad619a0a82262fc5 Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Wed, 26 Aug 2026 17:30:17 -0400 Subject: [PATCH] Document how to handle non-hal+json responses Addresses #134: by default, Hyperclient requires a Content-Type of application/hal+json and raises InvalidRepresentationError otherwise. This documents the existing workaround (broadening the response middleware's content_type matcher to /\bjson$/ via a custom connection block with default: false), confirmed working by the issue reporter. --- CHANGELOG.md | 1 + README.md | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07904be..ee3680c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * [#298](https://github.com/codegram/hyperclient/pull/300): Upgraded RuboCop to 1.80.2 - [@dblock](https://github.com/dblock). * [#298](https://github.com/codegram/hyperclient/pull/298): Upgraded RuboCop to 1.63.5 - [@dblock](https://github.com/dblock). +* [#320](https://github.com/codegram/hyperclient/pull/320): Documented how to handle non-`hal+json` responses via the Faraday response middleware's `content_type` matcher - [@dblock](https://github.com/dblock). * [#321](https://github.com/codegram/hyperclient/pull/321): Added Ruby 4.0 to the CI test matrix - [@dblock](https://github.com/dblock). * Your contribution here. diff --git a/README.md b/README.md index 58800c3..3bb42ff 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,8 @@ api = Hyperclient.new('https://grape-with-roar.herokuapp.com/api') do |client| end ``` +By default, Hyperclient requires responses to have a `Content-Type` of `application/hal+json`, and raises `Hyperclient::InvalidRepresentationError` otherwise. If your API sometimes returns responses that aren't `hal+json` (e.g. an empty body with a `201 Created`, or a plain `application/json` response), broaden the response middleware's `content_type` matcher as shown above (`content_type: /\bjson$/`) instead of the default, which only matches `hal+json`. + You can modify headers or specify authentication after a connection has been created. Hyperclient supports Basic, Token or [Digest auth](https://github.com/bhaberer/faraday-digestauth) as well as many other Faraday extensions. ```ruby