# httprip

> Manages queues of requests for data processing and collection.

Latest version **0.0.5** (published 2017-01-13) · MIT license · 0 weekly downloads

## Install

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

## 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.5 |
| Published | 2017-01-13 |
| First published | 2017-01-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Thomas Stiegler |
| Maintainers | tstiegler |
| Keywords | http, ripping, scraping, spider |

## Links

- npm: https://www.npmjs.com/package/httprip
- Repository: https://github.com/tstiegler/httprip
- Homepage: https://github.com/tstiegler/httprip#readme
- Issues: https://github.com/tstiegler/httprip/issues
- npm.io page: https://npm.io/package/httprip

## Dependencies (2)

- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [request](https://npm.io/package/request.md) latest

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.0.5 (latest) — 2017-01-13
- 0.0.4 — 2017-01-12
- 0.0.3 — 2017-01-12
- 0.0.2 — 2017-01-12
- 0.0.1 — 2017-01-12

## README

httprip - Manages queues of requests for data processing and collection.
========================================================================

[![Build Status](https://travis-ci.org/tstiegler/httprip.svg?branch=master)](https://travis-ci.org/tstiegler/httprip)

## Usage

```
npm install httprip
```

```javascript
var httprip = require("httprip");

var ripper = httprip()
    .processor(function(error, res, body, resolve) {
        // Perform parsing on body here.

        // Yield each item parse from body.
        ripper.yield("item" + Math.floor(Math.random() * 999));
        ripper.yield("item" + Math.floor(Math.random() * 999));

        // Resolve after we've finished processing.
        resolve();
    })
    .data(function(output) {
        console.log("Retrieved item:", output);
    });


// Queue requests.
ripper.enqueueRip({url: "http://google.com"});
ripper.enqueueRip({url: "http://yahoo.com"});
ripper.enqueueRip({url: "http://bing.com"});

// Wait for finish.
ripper.lastQueued().then(function() {
    console.log("done");
})
```

## Explanation

This project provides a shorthand API for processing multiple web requests that may have a common format with the end goal of extracting data. For example, My oroginal goal for this project was to extract a JSON object with all fonts on 1001fonts.com. The code for doing that is contained in `example.js`

Processing behavior is done declaratively by the `processor` and `data` methods. 

Functions supplied to `processor` are called with the usual `request` paramaters (`error`, `response` and `body`) as well as an additional `resolve`. `resolve` is a Promise resolver method and must be called at the end of processing, as processing may be asynchronous and `httprip` needs to know when the processing has been comleted. During the course of processing, you must run `yield` on the ripper object to submit a single element of data you are intending to collect.

Whilst the action you might take in the course of yielding an item _could_ be done in the processor method, the `yield` and `processor` methods allow you to submit multiple methods that will all be run for processing and yielding.

To send a request off to the ripper, the `enqueueRip` method is used. This method accepts a single `options` parameter, which is the same type of object you would give to the `request` module, giving you the power to custom craft your requests in any way you want.

Waiting for the last queued request to finish can be done by using the `lastQueued` method, which gives you the Promise for the last request in the queue.

## Methods

Method Name | Description
--- | ---
`enqueueRip` | Submits a request to the queue. <ul><li>`options` - Request Options</li></ul>
`lastQueued` | Gets the promise (which fires on completion) for the last request in the queue.
`processor` | Adds a processor function to the ripper processor chain, calling this function for each queued request.
`data` | Adds a data collector function to the ripper data collector chain. This method will be called for each yield.
`yield` | Yields a single element to all data collector functions. <ul><li>`item` - Item for forwarding to data collectors</li></ul>
`setRequester` | Sets the internal request instance. Useful for injecting a pre-made request object with defaults. <ul><li>`requester` - New request instance</li></ul>

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