npm package: @plasma-platform/tm-service-api
Description: Common tm microservice api methods
Author: Anton Nemtsev
Latest version: 2.5.0

# 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. -->

### Table of Contents

-   [ErrorBadRequest](#errorbadrequest)
-   [ErrorCache](#errorcache)
-   [ErrorNotFound](#errornotfound)
-   [ErrorServerResponse](#errorserverresponse)
-   [TMMicroServiceAPI](#tmmicroserviceapi)
    -   [url](#url)
    -   [token](#token)
    -   [messages](#messages)
    -   [setToken](#settoken)
    -   [setVersion](#setversion)
    -   [checkVersion](#checkversion)
    -   [request](#request)
-   [tmpVersion](#tmpversion)

## ErrorBadRequest

Custom error message for Bad Request server response

**Parameters**

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

## ErrorCache

Custom error message for cache fail

**Parameters**

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

## ErrorNotFound

Custom error message for Not Found server response

**Parameters**

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

## ErrorServerResponse

Custom error message for abstract server response

**Parameters**

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

## TMMicroServiceAPI

TM Micro Service Proto API

**Parameters**

-   `url` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** service url
-   `token` **([string](https://developer.mozilla.org/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/docs/Web/JavaScript/Reference/Global_Objects/String)** url

### token

User access token

**Properties**

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

### messages

Object with class service messages

### setToken

Set access token

**Parameters**

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

### setVersion

Set service version

**Parameters**

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

### checkVersion

Validate service version

**Parameters**

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


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

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

### request

Fetch remote resource

**Parameters**

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

Returns **[Promise](https://developer.mozilla.org/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/docs/Web/JavaScript/Reference/Global_Objects/String)?** service version