Sha256: 931861f5cb83e23d53b7baee2c6091e2a7b40e36fc5a859e383ce178743d704a

Contents?: true

Size: 755 Bytes

Versions: 30

Compression:

Stored size: 755 Bytes

Contents

module JsonApiClient
  module Middleware
    class JsonRequest < Faraday::Middleware
      def call(environment)
        accept_header = update_accept_header(environment[:request_headers])

        environment[:request_headers]["Content-Type"] = 'application/vnd.api+json'
        environment[:request_headers]["Accept"] = accept_header
        @app.call(environment)
      end

      private

      def update_accept_header(headers)
        return 'application/vnd.api+json' if headers["Accept"].nil?
        accept_params = headers["Accept"].split(",")

        unless accept_params.include?('application/vnd.api+json')
          accept_params.unshift('application/vnd.api+json')
        end

        accept_params.join(",")
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
json_api_client-1.23.0 lib/json_api_client/middleware/json_request.rb
json_api_client-1.22.0 lib/json_api_client/middleware/json_request.rb
json_api_client-1.21.1 lib/json_api_client/middleware/json_request.rb
json_api_client-1.21.0 lib/json_api_client/middleware/json_request.rb
json_api_client-1.20.0 lib/json_api_client/middleware/json_request.rb
json_api_client-1.19.0 lib/json_api_client/middleware/json_request.rb
carwow-json_api_client-1.19.0 lib/json_api_client/middleware/json_request.rb
json_api_client-1.18.0 lib/json_api_client/middleware/json_request.rb
json_api_client-1.17.1 lib/json_api_client/middleware/json_request.rb
json_api_client-1.17.0 lib/json_api_client/middleware/json_request.rb
json_api_client-1.16.1 lib/json_api_client/middleware/json_request.rb
json_api_client-1.16.0 lib/json_api_client/middleware/json_request.rb
json_api_client-1.15.0 lib/json_api_client/middleware/json_request.rb
json_api_client-1.14.1 lib/json_api_client/middleware/json_request.rb
json_api_client-1.14.0 lib/json_api_client/middleware/json_request.rb
json_api_client-1.13.0 lib/json_api_client/middleware/json_request.rb
json_api_client-1.12.2 lib/json_api_client/middleware/json_request.rb
json_api_client-1.12.1 lib/json_api_client/middleware/json_request.rb
json_api_client-1.12.0 lib/json_api_client/middleware/json_request.rb
json_api_client-1.11.0 lib/json_api_client/middleware/json_request.rb