Table of Contents

Class ElementEndpoint<TEntity>

Namespace
TypedRest.Endpoints.Generic
Assembly
TypedRest.dll

Endpoint for an individual resource.

public class ElementEndpoint<TEntity> : CachingEndpointBase, ICachingEndpoint, IElementEndpoint<TEntity>, IElementEndpoint, IEndpoint where TEntity : class

Type Parameters

TEntity

The type of entity the endpoint represents.

Inheritance
ElementEndpoint<TEntity>
Implements
Derived
Inherited Members

Constructors

ElementEndpoint(IEndpoint, string)

Creates a new element endpoint.

public ElementEndpoint(IEndpoint referrer, string relativeUri)

Parameters

referrer IEndpoint

The endpoint used to navigate to this one.

relativeUri string

The URI of this endpoint relative to the referrer's. Add a ./ prefix here to imply a trailing slash referrer's URI.

ElementEndpoint(IEndpoint, Uri)

Creates a new element endpoint.

public ElementEndpoint(IEndpoint referrer, Uri relativeUri)

Parameters

referrer IEndpoint

The endpoint used to navigate to this one.

relativeUri Uri

The URI of this endpoint relative to the referrer's.

Properties

DeleteAllowed

Indicates whether the server has specified DeleteAsync(CancellationToken) is currently allowed.

public bool? DeleteAllowed { get; }

Property Value

bool?

true if the method is allowed, false if the method is not allowed, null If no request has been sent yet or the server did not specify allowed methods.

Remarks

Uses cached data from last response.

MergeAllowed

Indicates whether the server has specified MergeAsync(TEntity, CancellationToken) is currently allowed.

public bool? MergeAllowed { get; }

Property Value

bool?

true if the method is allowed, false if the method is not allowed, null If no request has been sent yet or the server did not specify allowed methods.

Remarks

Uses cached data from last response.

Response

A cached copy of the entity as received from the server.

public TEntity? Response { get; }

Property Value

TEntity

SetAllowed

Indicates whether the server has specified SetAsync(TEntity, CancellationToken) is currently allowed.

public bool? SetAllowed { get; }

Property Value

bool?

true if the method is allowed, false if the method is not allowed, null If no request has been sent yet or the server did not specify allowed methods.

Remarks

Uses cached data from last response.

Methods

DeleteAsync(CancellationToken)

Deletes the element.

public virtual Task DeleteAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Used to cancel the request.

Returns

Task

Exceptions

InvalidOperationException

The entity has changed since it was last retrieved with ReadAsync(CancellationToken). Your delete call was rejected to prevent a lost update.

InvalidDataException

BadRequest

AuthenticationException

Unauthorized

UnauthorizedAccessException

Forbidden

KeyNotFoundException

NotFound or Gone

HttpRequestException

Other non-success status code.

ExistsAsync(CancellationToken)

Determines whether the element currently exists.

public Task<bool> ExistsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Used to cancel the request.

Returns

Task<bool>

Exceptions

AuthenticationException

Unauthorized

UnauthorizedAccessException

Forbidden

HttpRequestException

Other non-success status code.

MergeAsync(TEntity, CancellationToken)

Modifies an existing entity by merging changes on the server-side.

public Task<TEntity?> MergeAsync(TEntity entity, CancellationToken cancellationToken = default)

Parameters

entity TEntity

The entity data to merge with the existing one.

cancellationToken CancellationToken

Used to cancel the request.

Returns

Task<TEntity>

The modified entity as returned by the server, possibly with additional fields set. null if the server does not respond with a result entity.

Exceptions

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 entitiy.

public virtual Task<TEntity> ReadAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Used to cancel the request.

Returns

Task<TEntity>

Exceptions

AuthenticationException

Unauthorized

UnauthorizedAccessException

Forbidden

KeyNotFoundException

NotFound or Gone

HttpRequestException

Other non-success status code.

SetAsync(TEntity, CancellationToken)

Sets/replaces the entity.

public virtual Task<TEntity?> SetAsync(TEntity entity, CancellationToken cancellationToken = default)

Parameters

entity TEntity

The new entities.

cancellationToken CancellationToken

Used to cancel the request.

Returns

Task<TEntity>

The entity as returned by the server, possibly with additional fields set. null if the server does not respond with a result entity.

Exceptions

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<JsonPatchDocument<TEntity>>, int, 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.

public Task<TEntity?> UpdateAsync(Action<JsonPatchDocument<TEntity>> patchAction, int maxRetries = 3, CancellationToken cancellationToken = default)

Parameters

patchAction Action<JsonPatchDocument<TEntity>>

Callback for building a patch document describing the desired modifications.

maxRetries int

The maximum number of retries to perform for optimistic concurrency before giving up.

cancellationToken CancellationToken

Used to cancel the request.

Returns

Task<TEntity>

The entity as returned by the server, possibly with additional fields set. null if the server does not respond with a result entity.

Exceptions

InvalidOperationException

The number of retries performed for optimistic concurrency exceeded maxRetries.

NotSupportedException

Serializers does not contain a JsonMediaTypeFormatter.

InvalidDataException

BadRequest

AuthenticationException

Unauthorized

UnauthorizedAccessException

Forbidden

KeyNotFoundException

NotFound or Gone

HttpRequestException

Other non-success status code.

UpdateAsync(Action<TEntity>, int, CancellationToken)

Reads the current state of the entity, applies a change to it and stores the result. Applies optimistic concurrency using automatic retries.

public Task<TEntity?> UpdateAsync(Action<TEntity> updateAction, int maxRetries = 3, CancellationToken cancellationToken = default)

Parameters

updateAction Action<TEntity>

A callback that takes the current state of the entity and applies the desired modifications.

maxRetries int

The maximum number of retries to perform for optimistic concurrency before giving up.

cancellationToken CancellationToken

Used to cancel the request.

Returns

Task<TEntity>

The entity as returned by the server, possibly with additional fields set. null if the server does not respond with a result entity.

Exceptions

InvalidOperationException

The number of retries performed for optimistic concurrency exceeded maxRetries.

InvalidDataException

BadRequest

AuthenticationException

Unauthorized

UnauthorizedAccessException

Forbidden

KeyNotFoundException

NotFound or Gone

HttpRequestException

Other non-success status code.

UpdateAsync(Func<TEntity, TEntity>, int, CancellationToken)

Reads the current state of the entity, applies a change to it and stores the result. Applies optimistic concurrency using automatic retries.

public Task<TEntity?> UpdateAsync(Func<TEntity, TEntity> updateAction, int maxRetries = 3, CancellationToken cancellationToken = default)

Parameters

updateAction Func<TEntity, TEntity>

A callback that takes the current state of the entity and applies the desired modifications.

maxRetries int

The maximum number of retries to perform for optimistic concurrency before giving up.

cancellationToken CancellationToken

Used to cancel the request.

Returns

Task<TEntity>

The entity as returned by the server, possibly with additional fields set. null if the server does not respond with a result entity.

Exceptions

InvalidOperationException

The number of retries performed for optimistic concurrency exceeded maxRetries.

InvalidDataException

BadRequest

AuthenticationException

Unauthorized

UnauthorizedAccessException

Forbidden

KeyNotFoundException

NotFound or Gone

HttpRequestException

Other non-success status code.