Table of Contents

Class CRUDService<TClient, TData, TRequest, Tquery>

CRUDService is a generic base class for performing standard CRUD operations against a RESTful API. It provides methods to create, retrieve, update, delete, and list resources on the server using a specified endpoint.

If a specific operation is not needed, use object as a placeholder for the corresponding generic type. For example, if query options are not required, use object for Tquery.

public class CRUDService<TClient, TData, TRequest, Tquery> : CRUDServiceBase<TClient> where TClient : CRUDClient<TClient> where Tquery : Query

Type Parameters

TClient

The REST client type, which must inherit from CRUDClient<TSelf>.

TData

The type representing the resource data returned from the API.

TRequest

The type used when sending create or update requests to the API. Use object if creation and update operations are not supported.

Tquery

The type used for specifying query parameters when listing resources. Use object if listing is not supported.

Inheritance
CRUDService<TClient, TData, TRequest, Tquery>
Derived
Inherited Members
Extension Methods

Constructors

CRUDService(string, TClient, params RESTHeader[])

protected CRUDService(string endpoint, TClient client, params RESTHeader[] betaHeaders)

Parameters

endpoint string
client TClient
betaHeaders RESTHeader[]

CRUDService(string, TClient, bool, string)

protected CRUDService(string endpoint, TClient client, bool betaService = false, string customApiKey = null)

Parameters

endpoint string
client TClient
betaService bool
customApiKey string

CRUDService(string, TClient, string, params RESTHeader[])

protected CRUDService(string endpoint, TClient client, string customApiKey, params RESTHeader[] betaHeaders)

Parameters

endpoint string
client TClient
customApiKey string
betaHeaders RESTHeader[]

Fields

_endpoint

protected readonly string _endpoint

Field Value

string

_endpointWithId

protected readonly string _endpointWithId

Field Value

string

Methods

CreateAsync(TRequest, RequestOptions)

Creates a new resource on the server using the specified request body.

public UniTask<TData> CreateAsync(TRequest req, RequestOptions options = null)

Parameters

req TRequest

The data to send in the creation request.

options RequestOptions

Optional request options.

Returns

UniTask<TData>

The created resource.

Exceptions

InvalidOperationException

Thrown if TRequest is set to object.

DeleteAsync(string, RequestOptions)

Deletes a resource from the server using the specified identifier.

public UniTask<bool> DeleteAsync(string id, RequestOptions options = null)

Parameters

id string

The identifier of the resource to delete.

options RequestOptions

Optional request options.

Returns

UniTask<bool>

true if the resource was deleted successfully; otherwise, false.

ListAsync(Tquery, RequestOptions)

Retrieves a list of resources from the server, optionally filtered or paginated using query options.

public UniTask<QueryResponse<TData>> ListAsync(Tquery query = null, RequestOptions options = null)

Parameters

query Tquery

Optional query options for filtering, sorting, or pagination.

options RequestOptions

Optional request options.

Returns

UniTask<QueryResponse<TData>>

A list of resources wrapped in a QueryResponse<T>.

RetrieveAsync(string, RequestOptions)

Retrieves a resource from the server by its unique identifier.

public UniTask<TData> RetrieveAsync(string id, RequestOptions options = null)

Parameters

id string

The identifier of the resource to retrieve.

options RequestOptions

Optional request options.

Returns

UniTask<TData>

The retrieved resource.

UpdateAsync(string, IEnumerable<UpdateMask>, RequestOptions)

Partially updates an existing resource on the server using the specified identifier and update masks.

public UniTask<TData> UpdateAsync(string id, IEnumerable<UpdateMask> updateMasks, RequestOptions options = null)

Parameters

id string

The identifier of the resource to update.

updateMasks IEnumerable<UpdateMask>

The update masks specifying which fields to update.

options RequestOptions

Optional request options.

Returns

UniTask<TData>

The updated resource.

Exceptions

InvalidOperationException

Thrown if TRequest is set to object.

UpdateAsync(string, TRequest, RequestOptions)

Updates an existing resource on the server using the specified identifier and request body.

public UniTask<TData> UpdateAsync(string id, TRequest req, RequestOptions options = null)

Parameters

id string

The identifier of the resource to update.

req TRequest

The data to send in the update request.

options RequestOptions

Optional request options.

Returns

UniTask<TData>

The updated resource.

Exceptions

InvalidOperationException

Thrown if TRequest is set to object.