Table of Contents

Namespace TypedRest.Endpoints.Generic

Generic endpoints allow you to model collections and elements.

A collection endpoint represents a set of resources, and indexing it (or creating an entity in it) yields the element endpoint for an individual resource. Use an indexer endpoint instead when elements are addressable by ID but the set as a whole cannot be listed or added to.

UpdateAsync() combines a read and a write into a read-modify-write cycle. It uses the ETag from the read to send a conditional write and retries the whole cycle if the server reports a conflict, giving you optimistic concurrency without writing the retry loop yourself.

Whether the server actually permits an operation is discovered from the Allow header of the last response and exposed as nullable bool properties such as CreateAllowed or SetAllowed; null means "not known yet". These are handy for enabling or disabling controls in a UI without hard-coding the server's policy.

Each type comes in variants with an extra type parameter for the child endpoint type. Use them to plug in your own element endpoint, e.g. one that exposes further sub-resources:

class ContactEndpoint(IEndpoint referrer, Uri relativeUri) : ElementEndpoint<Contact>(referrer, relativeUri)
{
    public ElementEndpoint<Note> Note => new(this, relativeUri: "./note");
}

class MyClient(Uri uri) : EntryEndpoint(uri)
{
    public CollectionEndpoint<Contact, ContactEndpoint> Contacts => new(this, relativeUri: "./contacts");
}

Classes

CachingEndpointBase

Base class for building endpoints that use ETags and Last-Modified timestamps for caching and to avoid lost updates.

CollectionEndpointExtensions

Provides extension methods for IIndexerEndpoint<TElementEndpoint> and ICollectionEndpoint<TEntity, TElementEndpoint>.

CollectionEndpoint<TEntity>

Endpoint for a collection of TEntitys addressable as ElementEndpoint<TEntity>s.

CollectionEndpoint<TEntity, TElementEndpoint>

Endpoint for a collection of TEntitys addressable as TElementEndpoints.

ElementEndpoint<TEntity>

Endpoint for an individual resource.

IndexerEndpoint<TElementEndpoint>

Endpoint that addresses child TElementEndpoints by ID.

Interfaces

ICollectionEndpoint<TEntity>

Endpoint for a collection of TEntitys addressable as IElementEndpoint<TEntity>s.

ICollectionEndpoint<TEntity, TElementEndpoint>

Endpoint for a collection of TEntitys addressable as TElementEndpoints.

IElementEndpoint

Endpoint for an individual resource. Usually you will want to use the typed-variant of this interface: IElementEndpoint<TEntity>

IElementEndpoint<TEntity>

Endpoint for an individual resource.

IIndexerEndpoint<TElementEndpoint>

Endpoint that addresses child TElementEndpoints by ID.