# babel-plugin-s2s-axios-api

> generate axios api

Latest version **0.0.1** (published 2017-11-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-s2s-axios-api
pnpm add babel-plugin-s2s-axios-api
yarn add babel-plugin-s2s-axios-api
bun add babel-plugin-s2s-axios-api
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2017-11-17 |
| First published | 2017-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | progted |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-s2s-axios-api
- npm.io page: https://npm.io/package/babel-plugin-s2s-axios-api

## Dependencies (3)

- [s2s-utils](https://npm.io/package/s2s-utils.md) ^0.5.0
- [babel-types](https://npm.io/package/babel-types.md) ^6.26.0
- [babel-preset-es2015](https://npm.io/package/babel-preset-es2015.md) ^6.24.1

## Recent versions

- 0.0.1 (latest) — 2017-11-17

## README

# babel-plugin-s2s-axios-api

> generate axios api

## Install

```
$ yarn add --dev babel-plugin-s2s-axios-api
```

## Create axios-api template

You should create babel-plugin-s2s-axios-api template. \
In your node project, you create a folder named templates in the same direcotry at the package.json

`mkdir templates`

And create a axios-api.js

`touch templates/axios-api.js`

Write this code.

```js
import axios from "./config"
```
## Create a axios-api config file
You prepare shared configure file named `config.js` in `src/api/`. \
For example, write these codes.

```js
import axios from 'axios'

const API_ROOT = process.env.API_ROOT || 'http://localhost:8080'

axios.defaults.timeout = 5000
axios.defaults.baseURL = API_ROOT
axios.defaults.headers.post['Content-Type'] = 'application/json'

export default axios
```
## s2s.config.js

s2s-axios-api plugin watch the `src/api/*.js` files.

```js
module.exports = {
  watch: './**/*.js',
  plugins: [
    {
      test: /src\/apis\/(?!.*index).*\.js/,
      plugin: ['s2s-redux-axios-api']
    },
  ],
  templates: [
    {
      test: /src\/api\/.*\.js/, input: 'axios-api.js'
    }
  ]
}
```
## Start s2s

Start the s2s with yarn command

`yarn run s2s`

## Usage

#### When create a axios api file

When you create a `src/api/*.js`, the below code is inserted automatically.

```js
import axios from "./config"
```

#### In:

In the axios api file, type action name with camelcase such as `getPokemonRequest` and save it.

```js
import axios from "./config"
getPokemonRequest
```

It will be expanded like this.

#### Out:

```js
import axios from "./config"
export const getPokemonRequest = config => axios.get(``, config);
```
> ### Comment
> Well, this expand pattern can not handle various http request methods.

# Test

This plugin has two test files. \
First is babel plugin main test file named `test.js` on root directory. \
Next is a `test/index.js` that will be transformed by the plugin.

Run this command.

` npm run test`

Test will run and you can see what happen.

If you modify the target javascript source code, please change the `test/index.js`.

---
_Source: https://npm.io/package/babel-plugin-s2s-axios-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
