Install
yarn add @xtreamr/cla-request
//or
npm install @xtreamr/cla-request --save-dev
Use:
import Request from '@xtreamr/cla-request'
export const request = new Request()
request.init({ apiUrl: 'www.someapiurl.com' })
request.setBearer({ bearer: 'auth-token' })
request.fetch(path, options)
To mock data into development you could configure the request with two paremeters into constructor:
const mockData = {
'/product/{id}': async ({
query,
parameters,
optionsFetch
}) => {
return {
id: 1,
name: 'tv'
}
},
'/products': async () => {
return [
{
id: 1,
name: 'tv'
},
{
id: 2,
name: 'computer'
}
]
},
}
const mockOptions = {
disabled: false,
delay: 10,
all: false,
paths: {
'/product/{id}': true,
'/products': false,
},
},
export const request = new Request({
mockData,
mockOptions
})