1.0.3 • Published 4 years ago

@psff/services-api v1.0.3

Weekly downloads
1
License
-
Repository
-
Last release
4 years ago

@psff/services-api

Service to manage GQL requests with axios.

Getting started

  1. Setup the package as a dependencie.

    yarn add @psff/services-api
  2. Instance 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? AxiosRequestConfig
  • batching queries are batched by default
  • batchingOptions? ({batchMax?: number, batchInterval?: number}): Enable query batching. batchMax
    • batchMax (number): Maximum number of queries that will be batching before making the request
    • batchInterval (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);

Authorization

  apiClient.setAuthorization(basic, 'Basic');
  • token (string): autenticacion token.
  • type ('JWT' | 'Basic'): authorization type.
1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago