<commit_before>Build on top axios - https://github.com/mzabriskie/axios

Inspiration on Mappersmith - https://github.com/tulios/mappersmith

## Install

```
npm install rest-mapper
```

## Usage

```javascript
import Mapper from 'rest-mapper';

let API = new Mapper({
  host: 'http://you.api.domain/v1',

  intercept: {
    request: {
      before: function () {
        ui.showLoading();
      },
      error: function () {
        // no god, no
      }
    },
    response: {
      success: function () {
        ui.hideLoading();
      },
      error: function () {
        // oh my app
      }
    }
  },

  resources: {
    Auth: {
      signin: { url: '/access/signin', method: 'post' },
      recovery: { url: '/access/recovery' }
    },
    User: {
      save: { url: '/users/{id}', method: 'put' }
    },
    Products: {
      get: { url: '/products' }
    }
  }
});

API.Auth
  .signin({
    body: {
      username: 'foo',
      password: '<PASSWORD>'
    }
  })
  .then((data) => {
    // response
  });


API.User
  .save({
    supplant: { id: 3 },
    headers: {
      'Authorization': 'token YOUR_SECURE_TOKEN',
      'Foo': 'bar'
    },
    method: 'post' // you can override params
  })
  .then((data) => {
    // response
    console.log(response.data);
    console.log(response.status);
    console.log(response.statusText);
    console.log(response.headers);
    console.log(response.config);
  })
  .catch((err) => {
    // error
  });


API.Products
  .get({
    params: {
      page: 2 // ?page=2
    }
  })
  .then((data) => {
    // response
  });
```

## Docs

More docs are coming... But how this lib was build on axios, you can read more about here https://github.com/mzabriskie/axios

## Test

Tests are coming...

## Versions

### 1.1.1 :zap:
* Singleton pattern, better performance

### 1.1.0 :cyclone:
* Added interceptors

### 1.0.0 :star:
* Create the rest-mapper
* Call ajax requests build top on axios
* resources
* hosts<commit_msg>Change README<commit_after>Build on top axios - https://github.com/mzabriskie/axios

Inspiration on Mappersmith - https://github.com/tulios/mappersmith

## Install

```
npm install rest-mapper
```

## Usage

```javascript
import Mapper from 'rest-mapper';

let API = new Mapper({
  host: 'http://you.api.domain/v1',

  intercept: {
    request: {
      before: function (config) {
        ui.showLoading();
      },
      error: function (err) {
        // no god, no
      }
    },
    response: {
      success: function (responseData) {
        ui.hideLoading();
      },
      error: function (err) {
        // oh my app
      }
    }
  },

  resources: {
    Auth: {
      signin: { url: '/access/signin', method: 'post' },
      recovery: { url: '/access/recovery' }
    },
    User: {
      save: { url: '/users/{id}', method: 'put' } // {id} is supplant
    },
    Products: {
      get: { url: '/products' },
      getByDate: { url: '/products/date/{startDate}/{endDate}' }
    }
  }
});
```

#### Pass data using methods body, put or patch
```javascript
// POST /access/signin REQUEST username=foo&password=<PASSWORD>

API.Auth
  .signin({
    data: {
      username: 'foo',
      password: '<PASSWORD>'
    }
  })
  .then((data) => {
    // response
  });
```


#### Supplant example
```javascript
// POST /users/3

API.User
  .save({
    supplant: { id: 3 },
    headers: {
      'Authorization': 'token YOUR_SECURE_TOKEN',
      'Foo': 'bar'
    },
    method: 'post' // you can override params
  })
  .then((data) => {
    // response
    console.log(response.data);
    console.log(response.status);
    console.log(response.statusText);
    console.log(response.headers);
    console.log(response.config);
  })
  .catch((err) => {
    // error
  });
```

#### Get all products pass params by query string
```javascript
// GET /products?page=2

API.Products
  .get({
    params: {
      page: 2
    }
  })
  .then((data) => {
    // response
  });
```


#### Get products by range date example
```javascript
// GET /products/date/2015-11-30/2015-12-25?status=active

API.Products
  .getByDate({
    supplant: { startDate: '2015-11-30', endDate: '2015-12-25' },
    params: { status: 'active' }
  })
  .then((data) => {
    // response
  })
  .catch((err) => {
    // error
  })
  .then(() => {
    // complete
  });
```

## Docs

Docs are coming... But how this lib was build on axios, you can read more about here https://github.com/mzabriskie/axios

## Test

Tests are coming...

## Versions

### 1.1.2 :snowflake:
* Change intercept logic

### 1.1.1 :zap:
* Singleton pattern, better performance

### 1.1.0 :cyclone:
* Added interceptors

### 1.0.0 :star:
* Create the rest-mapper
* Call ajax requests build top on axios
* resources
* hosts
{'fraction_non_alphanumeric': 0.17622170509837107, 'fraction_numerical': 0.013116141315845145, 'mean_word_length': 2.2924791086350975, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 17, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4242290', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1639, 'n_words': 379}