Class JsonApiOperationsController
- Namespace
- JsonApiDotNetCore.Controllers
- Assembly
- JsonApiDotNetCore.dll
The base class to derive atomic:operations controllers from. This class delegates all work to BaseJsonApiOperationsController but adds attributes for routing templates. If you want to provide routing templates yourself, you should derive from BaseJsonApiOperationsController directly.
public abstract class JsonApiOperationsController : BaseJsonApiOperationsController
- Inheritance
-
JsonApiOperationsController
- Inherited Members
Constructors
JsonApiOperationsController(IJsonApiOptions, IResourceGraph, ILoggerFactory, IOperationsProcessor, IJsonApiRequest, ITargetedFields, IAtomicOperationFilter)
The base class to derive atomic:operations controllers from. This class delegates all work to BaseJsonApiOperationsController but adds attributes for routing templates. If you want to provide routing templates yourself, you should derive from BaseJsonApiOperationsController directly.
protected JsonApiOperationsController(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.
[HttpPost]
public override 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
}
}]
}