Skip to content

Handle non-hal+json responses #134

Closed

Description

@espen

Responses are currently required to be hal+json. The API we consume returns a 201 without data and a http header for a new location when we do a _post. The request is successful but Hyperclient gives a InvalidRepresentationError due to the response not being hal+json.

This works in v0.8.5 but not in the latest version due to 1c7dc4c

I'll provide a failing test later.

Activity

  1. dblock commented on Jan 31, 2018

    @dblock
    Collaborator

    You should be able to add the right headers or do something like

        conn.request :json
        conn.response :json, content_type: /\bjson$/

    If the README is not clear appreciate some PRs.

  2. espen commented on Jan 31, 2018

    @espen
    Author

    Thanks, overriding response content type works. I assumed the problem was due to the empty body.

    client.connection do |conn|
      conn.response :hal_json
    end
    

    This is the first hal-json API I'm using so not sure what the norm is. If it is normal to retrieve a response like this with empty body and without content-type then perhaps this user case should be more explicit in the readme (I can provide a PR for that). If this is some uncommon scenario then no worries.

  3. dblock commented on Jan 31, 2018

    @dblock
    Collaborator

    Please PR anything! Documentation never hurt.

  4. dblock commented on Aug 26, 2026

    @dblock
    Collaborator

    Hi @espen, I'm an AI assistant commenting on behalf of @dblock. We've opened #320 to document this workaround (broadening the response middleware's content_type matcher to /\bjson$/ via a custom connection block) directly in the README, right next to a very similar existing example. Closing this issue since the workaround is confirmed working and now documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions