Table of Contents

Class CachingEndpointBase

Namespace
TypedRest.Endpoints.Generic
Assembly
TypedRest.dll

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

public abstract class CachingEndpointBase : EndpointBase, ICachingEndpoint, IEndpoint
Inheritance
CachingEndpointBase
Implements
Derived
Inherited Members

Constructors

CachingEndpointBase(IEndpoint, string)

Creates a new endpoint with a relative URI.

protected CachingEndpointBase(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.

CachingEndpointBase(IEndpoint, Uri)

Creates a new endpoint with a relative URI.

protected CachingEndpointBase(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. Add a ./ prefix here to imply a trailing slash referrer's URI.

Properties

ResponseCache

A cached copy of the last response.

public ResponseCache? ResponseCache { get; set; }

Property Value

ResponseCache

Methods

DeleteContentAsync(CancellationToken, string)

Performs an Delete request on the Uri. Sets IfMatch if there is a cached ETag to detect lost updates.

protected Task DeleteContentAsync(CancellationToken cancellationToken, string caller = "unknown")

Parameters

cancellationToken CancellationToken

Used to cancel the request.

caller string

The name of the method calling this method.

Returns

Task

Exceptions

InvalidOperationException

The content has changed since it was last retrieved with GetContentAsync(CancellationToken, string). 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.

GetContentAsync(CancellationToken, string)

Performs an HTTP GET request on the Uri and caches the response if the server sends an ETag.

protected Task<HttpContent> GetContentAsync(CancellationToken cancellationToken, string caller = "unknown")

Parameters

cancellationToken CancellationToken

Used to cancel the request.

caller string

The name of the method calling this method.

Returns

Task<HttpContent>

The response of the request or the cached response if the server responded with NotModified.

Remarks

Sends If-None-Match header if there is already a cached ETag.

Exceptions

AuthenticationException

Unauthorized

UnauthorizedAccessException

Forbidden

KeyNotFoundException

NotFound or Gone or empty response body

HttpRequestException

Other non-success status code.

PutContentAsync(HttpContent, CancellationToken, string)

Performs an Put request on the Uri. Sets IfMatch if there is a cached ETag to detect lost updates.

protected Task<HttpResponseMessage> PutContentAsync(HttpContent content, CancellationToken cancellationToken, string caller = "unknown")

Parameters

content HttpContent

The content to send to the server.

cancellationToken CancellationToken

Used to cancel the request.

caller string

The name of the method calling this method.

Returns

Task<HttpResponseMessage>

The response message.

Exceptions

InvalidOperationException

The content has changed since it was last retrieved with GetContentAsync(CancellationToken, string). 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.