Usage
Methods and usage for an Apso Client
The ApsoClient
provides an entity()
method to interact with specific resources in the API. It allows you to chain different methods to build queries and perform CRUD operations.
entity(entityName: string): EntityClient
Creates an instance of EntityClient
for the specified entity.
entityName
: The name of the entity (e.g.,'users'
).
Example
where(filter: Record<string, any>): EntityClient
Adds a filter to the query.
filter
: The filter conditions (e.g.,{ status: 'active' }
).
Example
limit(limit: number): EntityClient
Limits the number of returned records.
limit
: The maximum number of records to return.
Example
get<T>(): Promise<T>
Performs a GET request to retrieve the records.
Example
post<T>(data: any): Promise<T>
Performs a POST request to create a new resource.
data
: The data to be sent in the request body.
Example
put<T>(data: any): Promise<T>
Performs a PUT request to update an existing resource.
data
: The data to be updated.
Example
delete<T>(): Promise<T>
Performs a DELETE request to remove a resource.
Example
Query Parameters
The SDK supports several query parameters for GET requests to filter, sort, or paginate data.
Available Query Methods
where(filter: Record<string, any>)
: Filter records (e.g.,{ active: true }
).limit(limit: number)
: Limit the number of returned records.offset(offset: number)
: Skip a number of records.page(page: number)
: Specify the page number for pagination.
Example
Error Handling
The ApsoClient
will throw an error if the request fails. Make sure to wrap your requests in try-catch blocks to handle errors appropriately.