# vendor-api
This is a proxy server for requests to Spotify and Apple APIs with caching data to MongoDB.

## Header custom fields  

X-Data-Timeout:  
* 0 - get data from APIs, save to mongo  
* greater than 0 - get data from mongo if available  
* less 0 - same as previous, but check that data was saved to mongo less than this number of seconds from now  

X-Background-Save:  
* 0 or empty - save data to mongo before returning results  
* other - run saving data to mongo in background, do not wait this to return data  


## Running application with Docker

**1.** Install [Docker](https://www.docker.com/).

**2.** Run the application locally

```bash
$ docker-compose up
```

Application will be up and running on port 8000.

Several environment variables must be set:

* Env for Apple Music API: ``APPLE_MUSICKIT_KEYID``, ``APPLE_MUSICKIT_KEY``
* Env for Spotify API: ``SPOTIFY_CLIENT_ID``, ``SPOTIFY_CLIENT_SECRET``
* Env for MongoDB: ``MONGODB_HOST``, ``MONGODB_PORT``, ``MONGODB_USER``, ``MONGODB_PASSWORD``, ``MONGODB_DATABASE``, ``MONGODB_AUTH_MECHANISM``
* Env for Auth: ``VENDORAPI_APPKEY``

Run tests

```bash
$ make test
```

Run code style checkers
```bash
$ make checkstyle
```

Run security checkers
```bash
$ make security
```

Run code prittifier
```bash
$ make prittify
```

Run pre-commit script (prittifier, code style & security checkers, tests)
```bash
$ make pre-commit
```
