Table of Contents

Class SingletonResourceClient<TModel, TResource, TResponse>

Namespace
Crews.PlanningCenter.Api.Models
Assembly
Crews.PlanningCenter.Api.dll

Provides a base class for making strongly-typed HTTP requests to a specified resource endpoint.

public abstract class SingletonResourceClient<TModel, TResource, TResponse> : ResourceClient<TModel> where TResource : JsonApiResource<TModel>, new() where TResponse : ResourceResponse<TResource>, new()

Type Parameters

TModel

The type representing the model contained in the Crews.Web.JsonApiClient.JsonApiResource.Attributes property of TResource.

TResource

The type representing the JSON:API resource structure.

TResponse

The type representing the Planning Center response data.

Inheritance
SingletonResourceClient<TModel, TResource, TResponse>
Derived
Inherited Members

Remarks

This class is intended to be inherited by clients that interact with RESTful APIs, providing protected methods for common HTTP operations such as GET, POST, PUT, and DELETE. It handles serialization and deserialization of resource data and wraps HTTP errors in a custom exception for improved error handling.

Constructors

SingletonResourceClient(HttpClient, Uri)

Provides a base class for making strongly-typed HTTP requests to a specified resource endpoint.

protected SingletonResourceClient(HttpClient httpClient, Uri uri)

Parameters

httpClient HttpClient

The HTTP client instance used to send requests to the resource endpoint. Must not be null.

uri Uri

The URI of the resource endpoint to which requests will be sent. Must not be null.

Remarks

This class is intended to be inherited by clients that interact with RESTful APIs, providing protected methods for common HTTP operations such as GET, POST, PUT, and DELETE. It handles serialization and deserialization of resource data and wraps HTTP errors in a custom exception for improved error handling.

Methods

DeleteAsync(CancellationToken)

Sends an asynchronous DELETE request to the specified resource endpoint.

protected Task DeleteAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task

A task representing the asynchronous operation.

Exceptions

JsonApiException

Thrown when the HTTP response indicates a failure status code.

GetAsync(CancellationToken)

Sends an asynchronous GET request to the specified resource endpoint and deserializes the response content.

protected Task<TResponse> GetAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<TResponse>

A task representing the asynchronous operation, containing the deserialized resource of type TResponse if deserialization is successful; otherwise, null.

Exceptions

JsonApiException

Thrown when the HTTP response indicates a failure status code.

PatchAsync(JsonApiDocument<TResource>, CancellationToken)

Sends an asynchronous patch request with the specified JSON:API document to the resource endpoint and deserializes the response content.

protected Task<TResponse> PatchAsync(JsonApiDocument<TResource> document, CancellationToken cancellationToken = default)

Parameters

document JsonApiDocument<TResource>

The JSON:API document to be sent in the patch request.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<TResponse>

A task representing the asynchronous operation, containing the deserialized resource of type TResponse if deserialization is successful; otherwise, null.

Exceptions

JsonApiException

Thrown when the HTTP response indicates a failure status code.

PatchAsync(TModel, CancellationToken)

Sends an asynchronous patch request with the specified resource data to the resource endpoint and deserializes the response content.

protected Task<TResponse> PatchAsync(TModel resource, CancellationToken cancellationToken = default)

Parameters

resource TModel

The resource data to be sent in the patch request.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task<TResponse>

A task representing the asynchronous operation, containing the deserialized resource of type TResponse if deserialization is successful; otherwise, null.

Exceptions

JsonApiException

Thrown when the HTTP response indicates a failure status code.

PostAsync(Uri, CancellationToken)

Sends an asynchronous POST request to the specified URI without a request body, typically used for triggering actions or operations on the server that do not require input data.

protected Task PostAsync(Uri uri, CancellationToken cancellationToken = default)

Parameters

uri Uri

The URI to which the POST request will be sent.

cancellationToken CancellationToken

A token to monitor for cancellation requests.

Returns

Task

A task representing the asynchronous operation.