Class CrudService<TClient, TRequest, TResponse, TDeletionStatus, 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.
Inheritance
Implements
Inherited Members
Namespace: Glitch9.IO.Networking.RESTApi
Assembly: Glitch9.IO.dll
Syntax
public class CrudService<TClient, TRequest, TResponse, TDeletionStatus, TQuery> : CrudServiceBase<TClient>, ICrudService where TClient : IApiClient where TDeletionStatus : class, IDeletionStatus where TQuery : class, IRequestParameterProvider
Type Parameters
| Name | Description |
|---|---|
| TClient | The REST client type, which must inherit from CloudApiClient<TClient>. |
| TRequest | The type used when sending create or update requests to the API. Use object if creation and update operations are not supported. |
| TResponse | The type representing the resource data returned from the API. |
| TDeletionStatus | The type representing the status of a deletion operation. Must implement IDeletionStatus. |
| TQuery | The type used for specifying query parameters when listing resources. Use object if listing is not supported. |
Constructors
| Edit this page View SourceCrudService(string, TClient, params string[])
Declaration
protected CrudService(string apiKey, TClient client, params string[] endpoints)
Parameters
| Type | Name | Description |
|---|---|---|
| string | apiKey | |
| TClient | client | |
| string[] | endpoints |
CrudService(TClient, params string[])
Declaration
protected CrudService(TClient client, params string[] endpoints)
Parameters
| Type | Name | Description |
|---|---|---|
| TClient | client | |
| string[] | endpoints |
Methods
| Edit this page View SourceCreateAsync(RequestOptions)
Creates a new resource on the server using the specified request body.
Declaration
public virtual UniTask<TResponse> CreateAsync(RequestOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| RequestOptions | options | Optional request options. |
Returns
| Type | Description |
|---|---|
| UniTask<TResponse> | The created resource. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown if |
CreateAsync(TRequest, RequestOptions)
POST. Creates a new resource on the server using the specified request body.
Declaration
public virtual UniTask<TResponse> CreateAsync(TRequest req, RequestOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TRequest | req | The data to send in the creation request. |
| RequestOptions | options | Optional request options. |
Returns
| Type | Description |
|---|---|
| UniTask<TResponse> | The created resource. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown if |
DeleteAsync(string, RequestOptions)
DELETE. Deletes a resource and returns deletion status.
Declaration
public virtual UniTask<TDeletionStatus> DeleteAsync(string id, RequestOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | |
| RequestOptions | options |
Returns
| Type | Description |
|---|---|
| UniTask<TDeletionStatus> | Deletion status implementing IDeletionStatus. |
GetRequestParams()
Declaration
protected virtual RequestParameter[] GetRequestParams()
Returns
| Type | Description |
|---|---|
| RequestParameter[] |
ListAsync(TQuery, RequestOptions)
GET. Retrieves a list of resources from the server, optionally filtered or paginated using query options.
Declaration
public virtual UniTask<Queried<TResponse>> ListAsync(TQuery query = null, RequestOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| TQuery | query | Optional query options for filtering, sorting, or pagination. |
| RequestOptions | options | Optional request options. |
Returns
| Type | Description |
|---|---|
| UniTask<Queried<TResponse>> | A list of resources wrapped in a Queried<T>. |
PrepareRequest(TRequest)
Prepares the request object before sending it to the server. This method can be overridden in derived classes to modify the request as needed.
Declaration
protected virtual TRequest PrepareRequest(TRequest req)
Parameters
| Type | Name | Description |
|---|---|---|
| TRequest | req |
Returns
| Type | Description |
|---|---|
| TRequest |
ReplaceAsync(string, TRequest, RequestOptions)
POST. Updates an existing resource on the server using the specified identifier and request body.
Declaration
public virtual UniTask<TResponse> ReplaceAsync(string id, TRequest req, RequestOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | The identifier of the resource to update. |
| TRequest | req | The data to send in the update request. |
| RequestOptions | options | Optional request options. |
Returns
| Type | Description |
|---|---|
| UniTask<TResponse> | The updated resource. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown if |
RetrieveAsync(string, RequestOptions)
GET. Retrieves a resource from the server by its unique identifier.
Declaration
public virtual UniTask<TResponse> RetrieveAsync(string id, RequestOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | The identifier of the resource to retrieve. |
| RequestOptions | options | Optional request options. |
Returns
| Type | Description |
|---|---|
| UniTask<TResponse> | The retrieved resource. |
UpdateAsync(string, IEnumerable<UpdateMask>, RequestOptions)
PATCH. Partially updates an existing resource on the server using the specified identifier and update masks.
Declaration
public virtual UniTask<TResponse> UpdateAsync(string id, IEnumerable<UpdateMask> updateMasks, RequestOptions options = null)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | The identifier of the resource to update. |
| IEnumerable<UpdateMask> | updateMasks | The update masks specifying which fields to update. |
| RequestOptions | options | Optional request options. |
Returns
| Type | Description |
|---|---|
| UniTask<TResponse> | The updated resource. |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown if |