1.0.3 • Published 5 years ago
@psff/services-api v1.0.3
@psff/services-api
Service to manage GQL requests with axios.
Getting started
Setup the package as a dependencie.
yarn add @psff/services-apiInstance the client
const apiClient = new ApiClient({
requestConfig: {
baseURL: process.env.VUE_APP_API_URL,
},
batching: true,
batchingOptions: {
batchMax: 100, // default value
batchInterval: 10, // default value
},
});ApiClient parameters:
requestConfig?AxiosRequestConfigbatchingqueries are batched by defaultbatchingOptions?({batchMax?: number, batchInterval?: number}): Enable query batching. batchMaxbatchMax(number): Maximum number of queries that will be batching before making the requestbatchInterval(number): How much time will be capturing queries before making the request
Request
apiClient
.query<{ node: any }>({
query: gqlQuery,
variables: { id: 0 },
batching: false // the default batching can be overwritten
})
.then((response) => response.node);
}Response inteceptors
apiClient.setResponseInterceptors(responseInterceptor, responseErrorInterceptor);Set headers
apiClient.setHeaders((headers: any) => {
headers['Content-Type'] = 'application/json';
headers.Accept = 'application/json';
});Set transformations
apiClient.setTransformations(transformRequest, transformResponse);transformRequest: AxiosRequestConfig.transformRequesttransformResponse: AxiosRequestConfig.transformResponse
Authorization
apiClient.setAuthorization(basic, 'Basic');token(string): autenticacion token.type('JWT' | 'Basic'): authorization type.