Table of Contents

Class CollectionEndpoint<TEntity, TElementEndpoint>

Namespace
TypedRest.Endpoints.Generic
Assembly
TypedRest.dll

Endpoint for a collection of TEntitys addressable as TElementEndpoints.

public class CollectionEndpoint<TEntity, TElementEndpoint> : CachingEndpointBase, ICachingEndpoint, ICollectionEndpoint<TEntity, TElementEndpoint>, IIndexerEndpoint<TElementEndpoint>, IEndpoint where TEntity : class where TElementEndpoint : class, IElementEndpoint<TEntity>

Type Parameters

TEntity

The type of individual elements in the collection.

TElementEndpoint

The type of IElementEndpoint<TEntity> to provide for individual TEntitys. Must have a public constructor with an IEndpoint and an Uri or string parameter.

Inheritance
CollectionEndpoint<TEntity, TElementEndpoint>
Implements
ICollectionEndpoint<TEntity, TElementEndpoint>
IIndexerEndpoint<TElementEndpoint>
Derived
Inherited Members
Extension Methods

Constructors

CollectionEndpoint(IEndpoint, string)

Creates a new element collection endpoint.

public CollectionEndpoint(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.

CollectionEndpoint(IEndpoint, Uri)

Creates a new element collection endpoint.

public CollectionEndpoint(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

CreateAllAllowed

Shows whether the server has indicated that CreateAllAllowed is currently allowed.

public bool? CreateAllAllowed { get; }

Property Value

bool?

An indicator whether the verb is allowed. If no request has been sent yet or the server did not specify allowed verbs null is returned.

Remarks

Uses cached data from last response.

CreateAllowed

Shows whether the server has indicated that CreateAsync(TEntity, CancellationToken) is currently allowed.

public bool? CreateAllowed { 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.

this[string]

Returns an element endpoint for a specific child element.

public virtual TElementEndpoint this[string id] { get; }

Parameters

id string

The ID identifying the entity.

Property Value

TElementEndpoint

this[TEntity]

Returns an ElementEndpoint<TEntity> for a specific child element.

public virtual TElementEndpoint this[TEntity entity] { get; }

Parameters

entity TEntity

An existing entity to extract the ID from.

Property Value

TElementEndpoint

RangeUnit

The value used for Unit.

public string RangeUnit { get; set; }

Property Value

string

ReadAllAllowed

Shows whether the server has indicated that ReadAllAsync(CancellationToken) is currently allowed.

public bool? ReadAllAllowed { 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.

ReadRangeAllowed

Shows whether the server has indicated that ReadRangeAsync(RangeItemHeaderValue, CancellationToken) is allowed.

public bool? ReadRangeAllowed { get; }

Property Value

bool?

An indicator whether the method is allowed. If no request has been sent yet.

Remarks

Uses cached data from last response.

SetAllAllowed

Shows whether the server has indicated that SetAllAllowed is currently allowed.

public bool? SetAllAllowed { get; }

Property Value

bool?

An indicator whether the verb is allowed. If no request has been sent yet or the server did not specify allowed verbs null is returned.

Remarks

Uses cached data from last response.

Methods

CreateAllAsync(IEnumerable<TEntity>, CancellationToken)

Adds (or updates) multiple entities as elements in the collection.

public virtual Task CreateAllAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default)

Parameters

entities IEnumerable<TEntity>

The entities to create or modify.

cancellationToken CancellationToken

Used to cancel the request.

Returns

Task

Remarks

Uses a link with the relation type bulk to determine the URI to POST to. Defaults to the relative URI bulk.

Exceptions

InvalidDataException

BadRequest

AuthenticationException

Unauthorized

UnauthorizedAccessException

Forbidden

InvalidOperationException

Conflict

HttpRequestException

Other non-success status code.

CreateAsync(TEntity, CancellationToken)

Adds a entity as a new element to the collection.

public virtual ITask<TElementEndpoint?> CreateAsync(TEntity entity, CancellationToken cancellationToken = default)

Parameters

entity TEntity

The new entity.

cancellationToken CancellationToken

Used to cancel the request.

Returns

ITask<TElementEndpoint>

An endpoint for the newly created entity; null if the server returned neither a "Location" header nor an entity with an ID in the response body.

Exceptions

InvalidDataException

BadRequest

AuthenticationException

Unauthorized

UnauthorizedAccessException

Forbidden

InvalidOperationException

Conflict

HttpRequestException

Other non-success status code.

HandleCapabilities(HttpResponseMessage)

Handles allowed HTTP methods and other capabilities reported by the server.

protected override void HandleCapabilities(HttpResponseMessage response)

Parameters

response HttpResponseMessage

ReadAllAsync(CancellationToken)

Returns all entities in the collection.

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

Parameters

cancellationToken CancellationToken

Used to cancel the request.

Returns

Task<List<TEntity>>

Exceptions

AuthenticationException

Unauthorized

UnauthorizedAccessException

Forbidden

KeyNotFoundException

NotFound or Gone

HttpRequestException

Other non-success status code.

ReadRangeAsync(RangeItemHeaderValue, CancellationToken)

Returns all entities within a specific range of the collection.

public virtual Task<PartialResponse<TEntity>> ReadRangeAsync(RangeItemHeaderValue range, CancellationToken cancellationToken = default)

Parameters

range RangeItemHeaderValue

The range of entities to retrieve.

cancellationToken CancellationToken

Used to cancel the request.

Returns

Task<PartialResponse<TEntity>>

A subset of the entities and the range they come from. May not exactly match the request range.

Exceptions

AuthenticationException

Unauthorized

UnauthorizedAccessException

Forbidden

KeyNotFoundException

NotFound or Gone

InvalidOperationException

The requested range is not satisfiable.

HttpRequestException

Other non-success status code.

SetAllAsync(IEnumerable<TEntity>, CancellationToken)

Replaces the entire content of the collection with new entities.

public Task SetAllAsync(IEnumerable<TEntity> entities, CancellationToken cancellationToken = default)

Parameters

entities IEnumerable<TEntity>

The new set of entities the collection shall contain.

cancellationToken CancellationToken

Used to cancel the request.

Returns

Task

Exceptions

InvalidDataException

BadRequest

AuthenticationException

Unauthorized

UnauthorizedAccessException

Forbidden

InvalidOperationException

The entities have changed since they were last retrieved with ReadAllAsync(CancellationToken). Your changes were rejected to prevent a lost update.

HttpRequestException

Other non-success status code.