# api-tailor

> A tool to swiftly tailor a fitting api

Latest version **1.1.2** (published 2015-09-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install api-tailor
pnpm add api-tailor
yarn add api-tailor
bun add api-tailor
```

## 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 | 1.1.2 |
| Published | 2015-09-27 |
| First published | 2015-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 (+7 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Nachos team |
| Maintainers | amirschl, cohenorco, eladbezalel, noamokman, omrilitov |
| Keywords | tailor, swift, mapper, rest, api, request |

## Links

- npm: https://www.npmjs.com/package/api-tailor
- Repository: https://github.com/nachos/api-tailor
- Issues: https://github.com/nachos/api-tailor/issues
- npm.io page: https://npm.io/package/api-tailor

## Dependencies (6)

- [q](https://npm.io/package/q.md) ^1.4.1
- [debug](https://npm.io/package/debug.md) ^2.2.0
- [lodash](https://npm.io/package/lodash.md) ^3.10.1
- [request](https://npm.io/package/request.md) ^2.61.0
- [url-join](https://npm.io/package/url-join.md) 0.0.1
- [path-to-regexp](https://npm.io/package/path-to-regexp.md) ^1.2.1

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2015-09-27
- 1.1.1 — 2015-09-22
- 1.1.0 — 2015-08-17
- 1.0.1 — 2015-07-28
- 1.0.0 — 2015-07-28

## README

# api-tailor

A tool to swiftly tailor a fitting api

<table>
  <thead>
    <tr>
      <th>Linux</th>
      <th>OSX</th>
      <th>Windows</th>
      <th>Coverage</th>
      <th>Dependencies</th>
      <th>DevDependencies</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td colspan="2" align="center">
        <a href="https://travis-ci.org/nachos/api-tailor"><img src="https://img.shields.io/travis/nachos/api-tailor.svg?style=flat-square"></a>
      </td>
      <td align="center">
        <a href="https://ci.appveyor.com/project/nachos/api-tailor"><img src="https://img.shields.io/appveyor/ci/nachos/api-tailor.svg?style=flat-square"></a>
      </td>
      <td align="center">
<a href='https://coveralls.io/r/nachos/api-tailor'><img src='https://img.shields.io/coveralls/nachos/api-tailor.svg?style=flat-square' alt='Coverage Status' /></a>
      </td>
      <td align="center">
        <a href="https://david-dm.org/nachos/api-tailor"><img src="https://img.shields.io/david/nachos/api-tailor.svg?style=flat-square"></a>
      </td>
      <td align="center">
        <a href="https://david-dm.org/nachos/api-tailor#info=devDependencies"><img src="https://img.shields.io/david/dev/nachos/api-tailor.svg?style=flat-square"/></a>
      </td>
    </tr>
  </tbody>
</table>

## Have a problem? Come chat with us!
[![Join the chat at https://gitter.im/nachos/api-tailor](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/nachos/api-tailor?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

## Installation
``` bash
$ [sudo] npm install api-tailor --save
```

## Examples
``` js
var tailor = require('api-tailor');

var client = tailor({
    host: 'http://yourserver.com/api',
    resources: {
      customers: {
        all: {
          method: 'GET',
          path: '/'
        },
        add: {
          method: 'POST',
          path: '/'
        },
        byName: {
          method: 'GET',
          path: '/:name' // url parameter
        },
        downloadLog: {
          method: 'GET',
          path: '/log',
          stream: true // response will return as stream
        },
        uploadLog: {
          method: 'POST',
          path: '/log',
          data: 'form' // data given will be treated as form data
        }
      }
    }
  });

client.customers.all()
  .then(function(customers) {
    // customers -> all data from get request to http://yourserver.com/api/customers/all
  });
  
client.customers.add({ name: 'nacho', address: 'nachos home 25, dip mountain, taco-ville' })
  .then(function() {
    // -> post request to http://yourserver.com/api/customers/
  });
  
client.customers.byName({}, { name: 'nacho' })
  .then(function(customer) {
    // customer -> get request to http://yourserver.com/api/customers/nacho
  });
  
client.customers.downloadLog()
  .then(function(stream) {
    stream.pipe(process.stdout); // stream -> get request to http://yourserver.com/api/customers/log
  });
  
client.customers.uploadLog({file: fs.createReadStream('file.txt')})
  .then(function() {
    // -> post request to http://yourserver.com/api/customers/log
  });
```

### Injectors
Use injectors to intercept outgoing or incoming data and manpulate it.

#### Token Injector Example
```js
  var token;

  client.inject({
    request: function (request) {
      request.headers = request.headers || {};

      if (token) {
        request.headers.Authorization = 'Bearer ' + token;
      }

      return Q.resolve(request);
    }
  });
```

## Run Tests
``` bash
$ npm test
```

## License

[MIT](LICENSE)

<sub><sup>*we never go out of style*</sup></sub>

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