HTTP requests have the wrong Content-Type header
Hello,
I have noticed that JsonApiClient::Resource sends HTTP requests with a "Content-Type: application/json" header. Here is what needs fixing:
- As per the JSON API specification: Requests that have a non-empty body (i.e. POST, PUT and PATCH requests) must have a "Content-Type: application/vnd.api+json" header.
- As per the HTTP specification: Requests without a body (i.e. GET and DELETE requests) do not need a Content-Type header.
This is a library that I plan on using in production if I can, so congrats.
I have a similar problem when accessing an endpoint implemented in another language where the developer had to roll their own implementation, and made some mistakes. I need to add a media header to all GET requests, and the content type has to be the standard media type for JSON API.
But I can't find where I make the change. I suspect it's in the middleware.
@JohnSmall You are correct in your assumption that it requires you to add it in the middleware. I ran into a similar issue and was able to override the headers by adding my own middleware class like so:
module Api
class Request < Faraday::Middleware
def call(environment)
environment[:request_headers]["Content-Type"] = "application/vnd.api+json,application/vnd.api+json;com.api.version=#{Base.version}"
environment[:request_headers]["Accept"] = "application/vnd.api+json,application/vnd.api+json;com.api.version=#{Base.version}"
environment[:request_headers]["User-Agent"] = "Api Ruby Client v0.1.0"
environment[:request_headers]["Authorization"] = "Token token=#{Base.access_token}"
@app.call(environment)
end
end
end
As per the example in the README
Thanks for the advice
Any idea how I would modify the middleware to deal with SSL client certificates?