Interface IElementEndpoint<TEntity>
Endpoint for an individual resource.
Inherited Members
Namespace: TypedRest.Endpoints.Generic
Assembly: TypedRest.dll
Syntax
public interface IElementEndpoint<TEntity> : IElementEndpoint, IEndpoint where TEntity : class
Type Parameters
Name | Description |
---|---|
TEntity | The type of entity the endpoint represents. |
Properties
MergeAllowed
Shows whether the server has indicated that MergeAsync(TEntity, CancellationToken) is currently allowed.
Declaration
Nullable<bool> MergeAllowed { get; }
Property Value
Type | Description |
---|---|
Nullable<Boolean> |
|
Remarks
Uses cached data from last response.
Response
A cached copy of the entity as received from the server.
Declaration
TEntity Response { get; }
Property Value
Type | Description |
---|---|
TEntity |
SetAllowed
Shows whether the server has indicated that SetAsync(TEntity, CancellationToken) is currently allowed.
Declaration
Nullable<bool> SetAllowed { get; }
Property Value
Type | Description |
---|---|
Nullable<Boolean> |
|
Remarks
Uses cached data from last response.
Methods
MergeAsync(TEntity, CancellationToken)
Modifies an existing TEntity
by merging changes on the server-side.
Declaration
Task<TEntity> MergeAsync(TEntity entity, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TEntity | entity | The |
CancellationToken | cancellationToken | Used to cancel the request. |
Returns
Type | Description |
---|---|
Task<TEntity> | The modified |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The entity has changed since it was last retrieved with ReadAsync(CancellationToken). Your changes were rejected to prevent a lost update. |
InvalidDataException | BadRequest |
AuthenticationException | Unauthorized |
UnauthorizedAccessException | Forbidden |
KeyNotFoundException | NotFound or Gone |
HttpRequestException | Other non-success status code. |
ReadAsync(CancellationToken)
Returns the TEntity
.
Declaration
Task<TEntity> ReadAsync(CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | Used to cancel the request. |
Returns
Type | Description |
---|---|
Task<TEntity> |
Exceptions
Type | Condition |
---|---|
AuthenticationException | Unauthorized |
UnauthorizedAccessException | Forbidden |
KeyNotFoundException | NotFound or Gone |
HttpRequestException | Other non-success status code. |
SetAsync(TEntity, CancellationToken)
Sets/replaces the TEntity
.
Declaration
Task<TEntity> SetAsync(TEntity entity, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
TEntity | entity | The new |
CancellationToken | cancellationToken | Used to cancel the request. |
Returns
Type | Description |
---|---|
Task<TEntity> | The |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The entity has changed since it was last retrieved with ReadAsync(CancellationToken). Your changes were rejected to prevent a lost update. |
InvalidDataException | BadRequest |
AuthenticationException | Unauthorized |
UnauthorizedAccessException | Forbidden |
KeyNotFoundException | NotFound or Gone |
HttpRequestException | Other non-success status code. |
UpdateAsync(Action<TEntity>, Int32, CancellationToken)
Reads the current state of the entity, applies a change to it and stores the result. Applies optimistic concurrency using automatic retries.
Declaration
Task<TEntity> UpdateAsync(Action<TEntity> updateAction, int maxRetries = 3, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
Action<TEntity> | updateAction | A callback that takes the current state of the entity and applies the desired modifications. |
Int32 | maxRetries | The maximum number of retries to perform for optimistic concurrency before giving up. |
CancellationToken | cancellationToken | Used to cancel the request. |
Returns
Type | Description |
---|---|
Task<TEntity> | The |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The number of retries performed for optimistic concurrency exceeded |
InvalidDataException | BadRequest |
AuthenticationException | Unauthorized |
UnauthorizedAccessException | Forbidden |
KeyNotFoundException | NotFound or Gone |
HttpRequestException | Other non-success status code. |
UpdateAsync(Action<JsonPatchDocument<TEntity>>, Int32, CancellationToken)
Applies a JSON Patch to the entity. Sends the patch instructions to the server for processing; falls back to local processing with optimistic concurrency if that fails.
Declaration
Task<TEntity> UpdateAsync(Action<JsonPatchDocument<TEntity>> patchAction, int maxRetries = 3, CancellationToken cancellationToken = null)
Parameters
Type | Name | Description |
---|---|---|
Action<JsonPatchDocument<TEntity>> | patchAction | Callback for building a patch document describing the desired modifications. |
Int32 | maxRetries | The maximum number of retries to perform for optimistic concurrency before giving up. |
CancellationToken | cancellationToken | Used to cancel the request. |
Returns
Type | Description |
---|---|
Task<TEntity> | The |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The number of retries performed for optimistic concurrency exceeded |
NotSupportedException | Serializer is not a JsonMediaTypeFormatter. |
InvalidDataException | BadRequest |
AuthenticationException | Unauthorized |
UnauthorizedAccessException | Forbidden |
KeyNotFoundException | NotFound or Gone |
HttpRequestException | Other non-success status code. |