Chi-Iroh / HubSpot-API

MIT License
0 stars 0 forks source link

Update the request class manager #4

Closed Mael-RABOT closed 1 year ago

Mael-RABOT commented 1 year ago

Update the request class manager

Instead of a bulky class managing the request, create a bigger class that implement a method for each request.


Here is an example of rule set:

image


Here is an example of implementation:

import * as ApiRoutes from "../config"

async function find<T>(target: ApiTarget, id: number | string, config?: AxiosRequestConfig): Promise<T> {
    const response = await axios.get(ApiRoutes[target] + "/" + id, config)

    return await response.data
}
Chi-Iroh commented 1 year ago

fetch is replaced by axios.XXX findAll, find and create methods are added to HttpRequestManager, send is removed Error handling is updated to correctly deal with axios errors.