Skip to content

Content type hal+json doesn't agree with Faraday MIME json type #82

@dylanfareed

Description

@dylanfareed

If you are making a request from a spec with setup that is something like this

Hyperclient.new('http://example.org/') do |client|
      client.connection(default: false) do |conn|
        conn.request :json
        conn.response :json
        conn.use Faraday::Adapter::Rack, app
      end
    end

FaradayMiddleware::EncodeJson will not convert the request to json because it isn't aware of 'application/hal+json'

We monkeypatched it locally to work around the problem but it still isn't pretty.

module FaradayMiddleware
  class EncodeJson < Faraday::Middleware
    MIME_TYPE = 'application/hal+json'.freeze
  end
end

Alternatively, resetting the client's content type to application/json will work.

Hyperclient.new('http://example.org/') do |client|
      client.headers['Content-Type'] = 'application/json'
      client.connection(default: false) do |conn|
        conn.request :json
        conn.response :json
        conn.use Faraday::Adapter::Rack, app
      end
    end

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions