Table of Contents

Class JsonApiContentNegotiator

Namespace
JsonApiDotNetCore.Middleware
Assembly
JsonApiDotNetCore.dll

Supports all classes in the .NET class hierarchy and provides low-level services to derived classes. This is the ultimate base class of all .NET classes; it is the root of the type hierarchy.

[PublicAPI]
public class JsonApiContentNegotiator : IJsonApiContentNegotiator
Inheritance
JsonApiContentNegotiator
Implements
Inherited Members

Constructors

JsonApiContentNegotiator(IJsonApiOptions, IHttpContextAccessor)

public JsonApiContentNegotiator(IJsonApiOptions options, IHttpContextAccessor httpContextAccessor)

Parameters

options IJsonApiOptions
httpContextAccessor IHttpContextAccessor

Methods

GetDefaultMediaType(IReadOnlyList<JsonApiMediaType>, JsonApiMediaType?)

Returns the JSON:API media type (possibly including extensions) to use when no Accept header was sent.

protected virtual JsonApiMediaType? GetDefaultMediaType(IReadOnlyList<JsonApiMediaType> possibleMediaTypes, JsonApiMediaType? requestMediaType)

Parameters

possibleMediaTypes IReadOnlyList<JsonApiMediaType>

The media types returned from GetPossibleMediaTypes().

requestMediaType JsonApiMediaType

The media type from in the Content-Type header.

Returns

JsonApiMediaType

The default media type to use, or null if not available.

GetPossibleMediaTypes()

Gets the list of possible combinations of JSON:API extensions that are available at the current endpoint. The set of extensions in the request body must always be the same as in the response body.

protected virtual IReadOnlyList<JsonApiMediaType> GetPossibleMediaTypes()

Returns

IReadOnlyList<JsonApiMediaType>

Remarks

Override this method to add support for custom JSON:API extensions. Implementations should take Extensions into account. During content negotiation, the first compatible entry with the highest number of extensions is preferred, but beware that clients can overrule this using quality factors in an Accept header.

IsOperationsEndpoint()

protected bool IsOperationsEndpoint()

Returns

bool

Negotiate()

Validates the Content-Type and Accept HTTP headers from the incoming request. Throws a JsonApiException if unsupported. Otherwise, returns the list of negotiated JSON:API extensions, which should always be a subset of Extensions.

public IReadOnlySet<JsonApiMediaTypeExtension> Negotiate()

Returns

IReadOnlySet<JsonApiMediaTypeExtension>