# @feizheng/http-rest-config

> A simple rest config for react project.

Latest version **2.5.1** (published 2020-09-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install @feizheng/http-rest-config
pnpm add @feizheng/http-rest-config
yarn add @feizheng/http-rest-config
bun add @feizheng/http-rest-config
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.5.1 |
| Published | 2020-09-17 |
| First published | 2019-11-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 9.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | feizheng |
| Maintainers | afeiship |

## Links

- npm: https://www.npmjs.com/package/@feizheng/http-rest-config
- Repository: https://github.com/afeiship/http-rest-config
- Homepage: https://github.com/afeiship/http-rest-config#readme
- Issues: https://github.com/afeiship/http-rest-config/issues
- npm.io page: https://npm.io/package/@feizheng/http-rest-config

## Dependencies (4)

- [@feizheng/next-tmpl](https://npm.io/package/@feizheng/next-tmpl.md) ^1.0.4
- [@feizheng/next-js-core2](https://npm.io/package/@feizheng/next-js-core2.md) ^2.6.0
- [@feizheng/next-content-type](https://npm.io/package/@feizheng/next-content-type.md) ^1.1.4
- [@feizheng/next-data-transform](https://npm.io/package/@feizheng/next-data-transform.md) ^1.1.2

## Recent versions

- 2.5.1 (latest) — 2020-09-17
- 2.5.0 — 2020-09-17
- 2.4.2 — 2020-05-24
- 2.4.0 — 2020-05-24
- 2.3.1 — 2020-05-24
- 2.3.0 — 2020-05-24
- 2.2.0 — 2020-01-14
- 2.1.1 — 2019-11-26
- 2.1.0 — 2019-11-25

## README

# http-rest-config
> A simple rest config for react project.

## installation
```shell
npm install -S @feizheng/http-rest-config
```

## expamle http:
```js
import nx from '@feizheng/next-js-core2';
import NxAxios from '@feizheng/next-axios';
const MyHttp = nx.declare({
  extends: NxAxios,
  methods: {
    getToken: function () {
      const {login} = AppBase.$.session;
      if (login) {
        return 'Bearer ' + login.token;
      }
      return null;
    },
    setRequestInterceptor: function () {
      this.axios.interceptors.request.use((config) => {
        const bearerToken = this.getToken();
        bearerToken && nx.mix(config.headers.common, {Authorization: bearerToken});
        return config;
      });
    },
    contentType: function () {
      return 'application/json; charset=utf-8';
    },
    transformParam: function (inData) {
      return JSON.stringify(inData);
    },
    toData: function (inResponse) {
      return inResponse.data;
    },
    error: function (inError) {
      //todo: search error:
    }
  }
});
```

## example config:
```js
export default {
  host: 'https://app.demo.com',
  request: ['/backend', 'urlencode'],
  items: [
    {
      items: {
        'login':  ['post', '/adminUser/login'],
        'logout': ['post', '/adminUser/logout']
      }
    },
    {
      request: ['/admin', 'json'],
      items: {
        'article_create': ['post', '/article/create'],
        'article_update': ['post', '/article/update'],
        'article_page':   ['get', '/article/page'],
      }
    },
    {
      request: ['/backend/pmall', 'json'],
      items: {
        'article_create': ['post', '/article/create'],
        'article_update': ['post', '/article/update'],
        'article_page':   ['get', '/article/page'],
      }
    }
  ]
};
```

## usage:
```js
import httpRestConfig from '@feizheng/http-rest-config';

export default nx.declare({
  statics: {
    init () {
      httpRestConfig(this, MyHttp, APIS);
    }
  }
});
```

---
_Source: https://npm.io/package/@feizheng/http-rest-config · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
