Class CRUDService<TClient, TData, TRequest, Tquery>
- Namespace
- Glitch9.IO.Networking.RESTApi
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
TClientThe REST client type, which must inherit from CRUDClient<TSelf>.
TDataThe type representing the resource data returned from the API.
TRequestThe type used when sending create or update requests to the API. Use object if creation and update operations are not supported.
TqueryThe type used for specifying query parameters when listing resources. Use object if listing is not supported.
- Inheritance
-
CRUDServiceBase<TClient>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
endpointstringclientTClientbetaHeadersRESTHeader[]
CRUDService(string, TClient, bool, string)
protected CRUDService(string endpoint, TClient client, bool betaService = false, string customApiKey = null)
Parameters
CRUDService(string, TClient, string, params RESTHeader[])
protected CRUDService(string endpoint, TClient client, string customApiKey, params RESTHeader[] betaHeaders)
Parameters
endpointstringclientTClientcustomApiKeystringbetaHeadersRESTHeader[]
Fields
_endpoint
protected readonly string _endpoint
Field Value
_endpointWithId
protected readonly string _endpointWithId
Field Value
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
reqTRequestThe data to send in the creation request.
optionsRequestOptionsOptional request options.
Returns
- UniTask<TData>
The created resource.
Exceptions
- InvalidOperationException
Thrown if
TRequestis 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
idstringThe identifier of the resource to delete.
optionsRequestOptionsOptional request options.
Returns
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
queryTqueryOptional query options for filtering, sorting, or pagination.
optionsRequestOptionsOptional 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
idstringThe identifier of the resource to retrieve.
optionsRequestOptionsOptional 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
idstringThe identifier of the resource to update.
updateMasksIEnumerable<UpdateMask>The update masks specifying which fields to update.
optionsRequestOptionsOptional request options.
Returns
- UniTask<TData>
The updated resource.
Exceptions
- InvalidOperationException
Thrown if
TRequestis 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
idstringThe identifier of the resource to update.
reqTRequestThe data to send in the update request.
optionsRequestOptionsOptional request options.
Returns
- UniTask<TData>
The updated resource.
Exceptions
- InvalidOperationException
Thrown if
TRequestis set to object.