@q2devops/datahelper
v0.0.4
Published
Q2 datahelper
Downloads
4
Readme
Datahelper
Datahelper is a utility library for interacting with the Q2 platform data services.
It uses the Axios library to make HTTP requests and supports dynamic requests, CRUD operations, batch operations, metadata retrieval, and more.
Installation
npm install @q2devops/datahelper
Usage
Create
async create (servicePath: string, modelParams: object, config?: { verbose: boolean }): Promise<AxiosResponse>
This function creates a new record using a POST request.
Parameters
- servicePath: The service path for the record.
- modelParams: An object containing the record data.
- config: An optional object containing the configuration options (e.g. verbose).
Returns
A promise that resolves to an AxiosResponse object.
Read
async read (servicePath: string, queryParams?: object, config?: { verbose: boolean }): : Promise<AxiosResponse>
This function retrieves records using a GET request.
Parameters
- servicePath: The service path for the record.
- queryParams: An optional object containing query parameters.
- config: An optional object containing the configuration options (e.g. verbose).
Returns
A promise that resolves to an AxiosResponse object.
Update
async update (servicePath: string, modelParams: object, config?: { verbose: boolean }): Promise<AxiosResponse>
This function updates an existing record using a POST request.
Parameters
- servicePath: The service path for the record.modelParams: An object containing the record data.
- modelParams: An object containing the updated record data.
- config: An optional object containing the configuration options (e.g. verbose).
Returns
A promise that resolves to an AxiosResponse object.
Delete
async delete (servicePath: string, modelParams: object, config?: { verbose: boolean }): : Promise<AxiosResponse>
This function deletes an existing record using a POST request.
Parameters
- servicePath: The service path for the record.
- modelParams: An object containing the record data.
- config: An optional object containing the configuration options (e.g. verbose).
Returns
A promise that resolves to an AxiosResponse object.
Dynamic request with error handling
Can use try catch when awaiting promise to catch error
try {
const response = await q2Dh.dynamicRequest(AcceptedMethods.get, 'https://example.com',true);
response?.data // do something with data.
}
catch(error){
// do something with error
}