rubyresttestingrest-clienthttp-accept-header

Accept header in ruby rest-client I believe causes return of an error code 404


I am passing the following request to ruby rest-client gem;

RestClient::Request.execute(method: :get,
                            url: Config['site_url'] + path,
                            verify_ssl: OpenSSL::SSL::VERIFY_NONE,
                            headers: { organisation: 'WEB',
                                       accept: 'application/vnd.xyz.v2+json' })

Gem Versions ruby version 2.3.3 rest-client 2.0.2

I have passed the same request to Postman and I get the response I expected.

I also have a v1 of the API that accepts just ":json" and this also responds as expected so my feeling is that it is something around the

accept: 'application/vnd.xyz.v2+json'

That is causing the problem but I'm not sure what exactly. As my feeling is if there was something wrong with the response then postman would also complain.

The documentation here https://github.com/rest-client/rest-client default request headers: rest-client sets

accept:*/*

Just in case I passed / (although I am assuming * means enter what you need) but this returned the v1 response.

The method, url and verify_ssl are working in multiple other requests. So I don't think there is any issue there either.

Anyone, have any suggestions? Thx


Solution

  • The problem wasn't the request, it was the API didn't recognise the user-agent from the ruby request. It also returned a 404 when I sent a curl request.

    When passing a

     User-Agent: 
    

    with a browser/mobile device, the API responded as expected.