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