Class JsonApiContentNegotiator
- Namespace
- JsonApiDotNetCore.Middleware
- Assembly
- JsonApiDotNetCore.dll
Performs content negotiation for JSON:API requests.
[PublicAPI]
public class JsonApiContentNegotiator : IJsonApiContentNegotiator
- Inheritance
-
JsonApiContentNegotiator
- Implements
- Inherited Members
Constructors
JsonApiContentNegotiator(IJsonApiOptions, IHttpContextAccessor)
public JsonApiContentNegotiator(IJsonApiOptions options, IHttpContextAccessor httpContextAccessor)
Parameters
optionsIJsonApiOptionshttpContextAccessorIHttpContextAccessor
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
possibleMediaTypesIReadOnlyList<JsonApiMediaType>The media types returned from GetPossibleMediaTypes().
requestMediaTypeJsonApiMediaTypeThe media type from in the Content-Type header.
Returns
- JsonApiMediaType
The default media type to use, or
nullif 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
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
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()