# cork

> An API utility belt for request.

Latest version **0.0.1** (published 2012-10-31) · 0 weekly downloads

## Install

```sh
npm install cork
pnpm add cork
yarn add cork
bun add cork
```

## 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 | 2012-10-31 |
| First published | 2012-10-31 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.6 |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+7 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Andrew Sliwinski |
| Maintainers | diy |

## Links

- npm: https://www.npmjs.com/package/cork
- Repository: https://github.com/thisandagain/cork
- npm.io page: https://npm.io/package/cork

## Dependencies (3)

- [async](https://npm.io/package/async.md) ~0.1.22
- [lodash](https://npm.io/package/lodash.md) ~0.8.1
- [request](https://npm.io/package/request.md) ~2.11.4

## Recent versions

- 0.0.1 (latest) — 2012-10-31

## README

## cork
#### An API utility belt for request.

[![Build Status](https://secure.travis-ci.org/thisandagain/cork.png)](http://travis-ci.org/thisandagain/cork)

Cork is a minimal layer that sits on top of the [request](https://github.com/mikeal/request) module and adds a few patterns that make working with 3rd party APIs simpler.

### Installation
```bash
npm install cork
```

### Basic Use
```javascript
var cork = require('cork');

// First, let's register a new service with the name "buzz" and a few defaults
cork.register('buzz', {
    'method':   'get',
    'headers':  {
        'x-api-key': 'someApiKeyGoesHere'
    },
    'json':     {}
    'timeout':  20000
});

// Next, let's make a request based on that service
cork.request('buzz', {
    'uri':      'https://api.geek.com/some/resource'
}, function (err, body) {
    console.dir(body); // Woo!
});

// Neato! But let's say we want to create another request and override some of the defaults
cork.request('buzz', {
    'method':   'post'
    'uri':      'https://api.geek.com/some/other/resource',
    'json':     {
        'foo': 'bar'
    }
}, function (err, body) {
    console.dir(body); // Huzzah!
});
```

### Base URIs
A base URI can be defined during registration by passing the optional `base` parameter:

```javascript
cork.register('dork', {
    base: 'http://api.nerd.com',
});

cork.request('dork', {
    uri: '/yet/another/resource'
}, function (err, body) {
    // Weee! 
});
```

### API Limits / Throttling
When registering a service, Cork accepts an optional `throttle` parameter which represents a request limit expressed in milliseconds. Any requests that subsequently hit the throttle limit will be queued and processed in FIFO order. For example, let's say that we are working with an API that only accepts 10 requests per second:

```javascript
cork.register('geek', {
    throttle: 100   // 1 request per 100 milliseconds
});
```

### Testing
```bash
npm test
```

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