# Tenfold HTTP Client

This repo exports helper functions to help capture metrics for API requests.

### Usage

```
import { getHttpClient, HttpClientOptions, TfHttpClient } from '@tenfold/http-client';

const opts: HttpClientOptions = { statsdConfig: ... }
const httpClient: TfHttpClient = getHttpClient(opts);

httpClient.post(...)
```

The `HttpClientOptions` interface for now only has one property: `statsdConfig`, which represents the configuration object for statsd. See the resources below for statsd docs.

#### Using the Tenfold Error Interceptor

On version v0.5.0 an error interceptor helper was added. The interceptor will handle Axios errors and convert them to Tenfold Api error format (see [https://github.com/tenfold/tenfold-api-responses-ts](tenfold-api-responses)). To use it, you need to:

```
import { getHttpClient, TfHttpClient, TfErrorHandler } from '@tenfold/http-client';

const httpClient: TfHttpClient = getHttpClient(opts);

httpClient.interceptors.response.use((response: AxiosResponse) => response, TfErrorHandler.createInterceptor(logger));

```

Where `logger` is an optional parameter to log errors.


### Developing

1. Clone the repo `git clone git@github.com:tenfold/libraries`
2. `cd ./libraries`
3. `yarn install`

The source files can be found on the `packages/http-client/src` folder and the tests can be found on the `test` folder. Make sure to add tests for all your changes. Also, make sure to create a branch from `master` to develop your changes.
To run the tests you can simply use the command `yarn test`. Once you're done with your changes, send a pull request to master and get reviews.

### Generating a tag

See instructions [here](../../README.md)

