# TM Micro Service API Prototype class

This class provide fetch wrapper, token and Service URL setter mainly. Just to avoid code duplication.

## Requirements

Possibly you will need babel-polyfill to use it.

# Documentation

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

## ErrorBadRequest

**Extends Error**

Custom error message for Bad Request server response

**Parameters**

-   `message` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | null)** error details (optional, default `null`)

### constructor

Constructor generates errorinstance

**Parameters**

-   `message` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | null)** error details (optional, default `null`)

Returns **[ErrorBadRequest](#errorbadrequest)** current instance

## ErrorNotFound

**Extends Error**

Custom error message for Not Found server response

**Parameters**

-   `message` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | null)** error details (optional, default `null`)

### constructor

Constructor generates error instance

**Parameters**

-   `message` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | null)** error details (optional, default `null`)

Returns **[ErrorNotFound](#errornotfound)** current instance

## ErrorServerResponse

**Extends Error**

Custom error message for abstract server response

**Parameters**

-   `statusCode` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** http status code
-   `statusText` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** http status code text
-   `message` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | null)** error details (optional, default `null`)

### constructor

Constructor generates error instance

**Parameters**

-   `statusCode` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** http status code
-   `statusText` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** http status code text
-   `message` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | null)** error details (optional, default `null`)

Returns **[ErrorServerResponse](#errorserverresponse)** current instance

## TMMicroServiceAPI

TM Micro Service Proto API

**Parameters**

-   `url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** service url
-   `token` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | null)** user access tocken if available (optional, default `null`)

### url

Service URL

**Properties**

-   `service` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** url

### token

User access token

**Properties**

-   `token` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | null)?** user access tocken if available

### constructor

Constructor saves service url

**Parameters**

-   `url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** service url
-   `token` **([string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String) | null)** user access tocken if available (optional, default `null`)
-   `version` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** service version (optional, default `'v1'`)

Returns **[TMMicroServiceAPI](#tmmicroserviceapi)** current instance

### messages

Object with class service messages

### setToken

Set access token

**Parameters**

-   `token` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** access token

### setVersion

Set service version

**Parameters**

-   `version` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** service version

### checkUrl

Validagte URL

**Parameters**

-   `url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** service URL


-   Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** if URL do not match format Error will be thrown

Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** url - service URL

### checkVersion

Validate service version

**Parameters**

-   `version` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** service version


-   Throws **[Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)** if URL do not match format Error will be thrown

Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** version - service version

### request

Fetch remote resource

**Parameters**

-   `url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** resource url
-   `userOptions` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** user defined options

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** Promise with server [Response](https://developer.mozilla.org/docs/Web/API/Response)

## tmpVersion

Service version

**Properties**

-   `version` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** service version
