Table of Contents

Class ResourceClient<TModel>

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 ResourceClient<TModel>

Type Parameters

TModel

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

Inheritance
ResourceClient<TModel>
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

ResourceClient(HttpClient, Uri)

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

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

Properties

HttpClient

The HTTP client instance used to send requests to the resource endpoint.

protected HttpClient HttpClient { get; }

Property Value

HttpClient

Uri

The URI of the resource endpoint to which requests will be sent. This property is initialized in the constructor and can be modified using the provided methods for managing query parameters.

protected Uri Uri { get; set; }

Property Value

Uri

Methods

AddCustomParameter(string, string)

Adds a custom query parameter and its associated value to the instance's URI.

public ResourceClient<TModel> AddCustomParameter(string parameter, string value)

Parameters

parameter string

The name of the query parameter to be added.

value string

The value of the query parameter to be added.

Returns

ResourceClient<TModel>

AddQueryParameter(string, string)

Appends a value to a query parameter in the instance's URI, preserving any existing values for that parameter.

protected ResourceClient<TModel> AddQueryParameter(string parameter, string value)

Parameters

parameter string

The name of the query parameter.

value string

The value to append to the parameter.

Returns

ResourceClient<TModel>

ClearParameters()

Removes the entire query string from the instance's URI.

public ResourceClient<TModel> ClearParameters()

Returns

ResourceClient<TModel>

EnsureSuccessAsync(HttpResponseMessage, CancellationToken)

Reads the response content and throws a JsonApiException if the response indicates failure.

protected static Task EnsureSuccessAsync(HttpResponseMessage response, CancellationToken cancellationToken)

Parameters

response HttpResponseMessage
cancellationToken CancellationToken

Returns

Task

ReplaceQueryParameter(string, string)

Sets a query parameter in the instance's URI, replacing any existing value for that parameter.

protected ResourceClient<TModel> ReplaceQueryParameter(string parameter, string value)

Parameters

parameter string

The name of the query parameter.

value string

The value to set for the parameter.

Returns

ResourceClient<TModel>