Class BaseJsonApiOperationsController
- Namespace
- JsonApiDotNetCore.Controllers
- Assembly
- JsonApiDotNetCore.dll
Implements the foundational ASP.NET controller layer in the JsonApiDotNetCore architecture for handling atomic:operations requests. See https://jsonapi.org/ext/atomic/ for details. Delegates work to IOperationsProcessor.
[PublicAPI]
public abstract class BaseJsonApiOperationsController : CoreJsonApiController
- Inheritance
-
BaseJsonApiOperationsController
- Derived
- Inherited Members
Constructors
BaseJsonApiOperationsController(IJsonApiOptions, IResourceGraph, ILoggerFactory, IOperationsProcessor, IJsonApiRequest, ITargetedFields, IAtomicOperationFilter)
protected BaseJsonApiOperationsController(IJsonApiOptions options, IResourceGraph resourceGraph, ILoggerFactory loggerFactory, IOperationsProcessor processor, IJsonApiRequest request, ITargetedFields targetedFields, IAtomicOperationFilter operationFilter)
Parameters
options
IJsonApiOptionsresourceGraph
IResourceGraphloggerFactory
ILoggerFactoryprocessor
IOperationsProcessorrequest
IJsonApiRequesttargetedFields
ITargetedFieldsoperationFilter
IAtomicOperationFilter
Methods
PostOperationsAsync(IList<OperationContainer>, CancellationToken)
Atomically processes a list of operations and returns a list of results. All changes are reverted if processing fails. If processing succeeds but none of the operations returns any data, then HTTP 201 is returned instead of 200.
public virtual Task<IActionResult> PostOperationsAsync(IList<OperationContainer> operations, CancellationToken cancellationToken)
Parameters
operations
IList<OperationContainer>cancellationToken
CancellationToken
Returns
Examples
The next example creates a new resource.
POST /operations HTTP/1.1
Content-Type: application/vnd.api+json;ext="https://jsonapi.org/ext/atomic"
{
"atomic:operations": [{
"op": "add",
"data": {
"type": "authors",
"attributes": {
"name": "John Doe"
}
}
}]
}
The next example updates an existing resource.
POST /operations HTTP/1.1
Content-Type: application/vnd.api+json;ext="https://jsonapi.org/ext/atomic"
{
"atomic:operations": [{
"op": "update",
"data": {
"type": "authors",
"id": 1,
"attributes": {
"name": "Jane Doe"
}
}
}]
}
The next example deletes an existing resource.
POST /operations HTTP/1.1
Content-Type: application/vnd.api+json;ext="https://jsonapi.org/ext/atomic"
{
"atomic:operations": [{
"op": "remove",
"ref": {
"type": "authors",
"id": 1
}
}]
}
ValidateEnabledOperations(IList<OperationContainer>)
protected virtual void ValidateEnabledOperations(IList<OperationContainer> operations)
Parameters
operations
IList<OperationContainer>
ValidateModelState(IList<OperationContainer>)
protected virtual void ValidateModelState(IList<OperationContainer> operations)
Parameters
operations
IList<OperationContainer>