Table of Contents

Interface IJsonApiOptions

Namespace
JsonApiDotNetCore.Configuration
Assembly
JsonApiDotNetCore.dll

Global options that configure the behavior of JsonApiDotNetCore.

public interface IJsonApiOptions

Properties

AllowClientGeneratedIds

Whether clients can provide IDs when creating resources. When not allowed, a 403 Forbidden response is returned if a client attempts to create a resource with a defined ID. false by default.

[PublicAPI]
[Obsolete("Use ClientIdGeneration instead.")]
bool AllowClientGeneratedIds { get; }

Property Value

bool

Remarks

Setting this to true corresponds to Allowed, while false corresponds to Forbidden.

AllowUnknownFieldsInRequestBody

Whether to produce an error on unknown attribute and relationship keys in request bodies. false by default.

bool AllowUnknownFieldsInRequestBody { get; }

Property Value

bool

AllowUnknownQueryStringParameters

Whether to produce an error on unknown query string parameters. false by default.

bool AllowUnknownQueryStringParameters { get; }

Property Value

bool

ClientIdGeneration

Whether clients are allowed or required to provide IDs when creating resources. Forbidden by default. This setting can be overruled per resource type using ClientIdGeneration.

ClientIdGenerationMode ClientIdGeneration { get; }

Property Value

ClientIdGenerationMode

DefaultAttrCapabilities

Specifies the default set of allowed capabilities on JSON:API attributes. Defaults to All. This setting can be overruled per attribute using Capabilities.

AttrCapabilities DefaultAttrCapabilities { get; }

Property Value

AttrCapabilities

DefaultHasManyCapabilities

Specifies the default set of allowed capabilities on JSON:API to-many relationships. Defaults to All. This setting can be overruled per relationship using Capabilities.

HasManyCapabilities DefaultHasManyCapabilities { get; }

Property Value

HasManyCapabilities

DefaultHasOneCapabilities

Specifies the default set of allowed capabilities on JSON:API to-one relationships. Defaults to All. This setting can be overruled per relationship using Capabilities.

HasOneCapabilities DefaultHasOneCapabilities { get; }

Property Value

HasOneCapabilities

DefaultPageSize

The page size (10 by default) that is used when not specified in query string. Set to null to not use pagination by default.

PageSize? DefaultPageSize { get; }

Property Value

PageSize

EnableLegacyFilterNotation

Determines whether legacy filter notation in query strings (such as =eq:, =like:, and =in:) is enabled. false by default.

bool EnableLegacyFilterNotation { get; }

Property Value

bool

IncludeExceptionStackTraceInErrors

Whether to include Exception stack traces in Meta responses. false by default.

bool IncludeExceptionStackTraceInErrors { get; }

Property Value

bool

IncludeJsonApiVersion

Whether to include a 'jsonapi' object in responses, which contains the highest JSON:API version supported. false by default.

bool IncludeJsonApiVersion { get; }

Property Value

bool

IncludeRequestBodyInErrors

Whether to include the request body in Meta responses when it is invalid. false by default.

bool IncludeRequestBodyInErrors { get; }

Property Value

bool

IncludeTotalResourceCount

Whether to include the total resource count in top-level meta objects. This requires an additional database query. false by default.

bool IncludeTotalResourceCount { get; }

Property Value

bool

MaximumIncludeDepth

Controls how many levels deep includes are allowed to be nested. For example, MaximumIncludeDepth=1 would allow ?include=articles but not ?include=articles.revisions. null by default, which means unconstrained.

int? MaximumIncludeDepth { get; }

Property Value

int?

MaximumOperationsPerRequest

Limits the maximum number of operations allowed per atomic:operations request. Defaults to 10. Set to null for unlimited.

int? MaximumOperationsPerRequest { get; }

Property Value

int?

MaximumPageNumber

The maximum page number that can be used, or null for unconstrained (default).

PageNumber? MaximumPageNumber { get; }

Property Value

PageNumber

MaximumPageSize

The maximum page size that can be used, or null for unconstrained (default).

PageSize? MaximumPageSize { get; }

Property Value

PageSize

Namespace

The URL prefix to use for exposed endpoints.

string? Namespace { get; }

Property Value

string

Examples

options.Namespace = "api/shopping";

Configures which links to write in the RelationshipLinks object. Defaults to All. This setting can be overruled for all relationships per resource type by adding ResourceLinksAttribute on the class definition of a resource. This can be further overruled per relationship by setting Links.

LinkTypes RelationshipLinks { get; }

Property Value

LinkTypes

Configures which links to write in the ResourceLinks object. Defaults to All. This setting can be overruled per resource type by adding ResourceLinksAttribute on the class definition of a resource.

LinkTypes ResourceLinks { get; }

Property Value

LinkTypes

SerializerOptions

Enables to customize the settings that are used by the JsonSerializer.

JsonSerializerOptions SerializerOptions { get; }

Property Value

JsonSerializerOptions

Examples

The next example sets the naming convention to camel casing.

options.SerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
options.SerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;

SerializerReadOptions

Gets the settings used for deserializing request bodies. This value is based on SerializerOptions and is intended for internal use.

JsonSerializerOptions SerializerReadOptions { get; }

Property Value

JsonSerializerOptions

SerializerWriteOptions

Gets the settings used for serializing response bodies. This value is based on SerializerOptions and is intended for internal use.

JsonSerializerOptions SerializerWriteOptions { get; }

Property Value

JsonSerializerOptions

Configures which links to write in the TopLevelLinks object. Defaults to All. This setting can be overruled per resource type by adding ResourceLinksAttribute on the class definition of a resource.

LinkTypes TopLevelLinks { get; }

Property Value

LinkTypes

TransactionIsolationLevel

Enables to override the default isolation level for database transactions, enabling to balance between consistency and performance. Defaults to null, which leaves this up to Entity Framework Core to choose (and then it varies per database provider).

IsolationLevel? TransactionIsolationLevel { get; }

Property Value

IsolationLevel?

Whether to use relative links for all resources. false by default.

bool UseRelativeLinks { get; }

Property Value

bool
options.UseRelativeLinks = true;
{
  "type": "articles",
  "id": "4309",
  "relationships": {
     "author": {
       "links": {
         "self": "/api/shopping/articles/4309/relationships/author",
         "related": "/api/shopping/articles/4309/author"
       }
     }
  }
}

ValidateModelState

Whether ASP.NET ModelState validation is enabled. true by default.

bool ValidateModelState { get; }

Property Value

bool