Search Results for

    Show / Hide Table of Contents

    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
    object
    CrudServiceBase<TClient>
    CrudService<TClient, TRequest, TResponse, TDeletionStatus, TQuery>
    ModelService
    CachedContentService
    CorporaService
    FileService
    BatchService
    ModelService
    BatchService
    BetaService.AssistantService
    ContainersService
    FineTuningJobService
    ModelService
    VectorStoreService
    Implements
    ICrudService
    Inherited Members
    CrudServiceBase<TClient>.client
    CrudServiceBase<TClient>.ApiKey
    CrudServiceBase<TClient>.GetUrl(params string[])
    CrudServiceBase<TClient>.GetChildUrl(string, params string[])
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    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 Source

    CrudService(string, TClient, params string[])

    Declaration
    protected CrudService(string apiKey, TClient client, params string[] endpoints)
    Parameters
    Type Name Description
    string apiKey
    TClient client
    string[] endpoints
    | Edit this page View Source

    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 Source

    CreateAsync(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 TRequest is set to object.

    | Edit this page View Source

    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 TRequest is set to object.

    | Edit this page View Source

    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.

    | Edit this page View Source

    GetRequestParams()

    Declaration
    protected virtual RequestParameter[] GetRequestParams()
    Returns
    Type Description
    RequestParameter[]
    | Edit this page View Source

    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>.

    | Edit this page View Source

    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
    | Edit this page View Source

    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 TRequest is set to object.

    | Edit this page View Source

    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.

    | Edit this page View Source

    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 TRequest is set to object.

    Implements

    ICrudService

    Extension Methods

    ArrayExtensions.ToArrayOrEmpty<T>(T)
    ArrayExtensions.ToArrayOrNull<T>(T)
    EventExtensions.ToDelta<T>(T, string, int, string, bool)
    EventExtensions.ToDone<T>(T, string, int, string)
    EventExtensions.ToEvent<T>(T)
    EventExtensions.UpcastDelta<T1, T2>(T1, string, int, string, bool)
    FallbackExtensions.IsOr<TParent, TChild>(TParent, TChild)
    ResponseCastingExtensions.GetResult<T>(T)
    SystemExtensions.GetName(object)
    • Edit this page
    • View Source
    In this article
    Back to top AI DevKit Documentation