Skip to content

Allow use of version in Accept Header #874

@pixelhandler

Description

@pixelhandler

Allow versioning of an API endpoint via Accept header like so:

application/vnd.api+json;version=1

Perhaps allow for configuration to allow the check to use a loose match of "begins with" for the accept header.

The JSON API spec concluded without any media type parameters

Clients that include the JSON API media type in their Accept header MUST specify the media type there at least once without any media type parameters.

But that limits a good strategy for versioning an API endpoint via Accept Header. The Accept header generally allows media type parameters, see https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

Motivations:

Related Comment on the spec - json-api/json-api#406 (comment)

It would be great if ActsAsResourceController#valid_accept_media_type? could accept "application/vnd.api+json;version=1"

For example, I use https://github.com/EDMC/api-versions

The workaround is to re-define the method like so:

def valid_accept_media_type?
  media_types = media_types_for('Accept')

  media_types.blank? ||
    media_types.any? do |media_type|
      (media_type.start_with?(JSONAPI::MEDIA_TYPE) || media_type.start_with?(ALL_MEDIA_TYPES))
    end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions