# webmiddle-service-http-request

> > Service built on top of the [request](https://github.com/request/request) library, it is used to perform http requests.

Latest version **0.3.0** (published 2018-04-12) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install webmiddle-service-http-request
pnpm add webmiddle-service-http-request
yarn add webmiddle-service-http-request
bun add webmiddle-service-http-request
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2018-04-12 |
| First published | 2016-06-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | ^6.9.0 \|\| >=8.0.0 |
| Dependencies | 2 |
| Unpacked size | 18.3 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Manuel Dell'Elce |
| Maintainers | maluen |
| Keywords | web, data, integration, extraction, scraper, jsx, framework |

## Links

- npm: https://www.npmjs.com/package/webmiddle-service-http-request
- Repository: https://github.com/webmiddle/webmiddle
- Homepage: https://github.com/webmiddle/webmiddle#readme
- Issues: https://github.com/webmiddle/webmiddle/issues
- npm.io page: https://npm.io/package/webmiddle-service-http-request

## Dependencies (2)

- [request](https://npm.io/package/request.md) ^2.72.0
- [webmiddle](https://npm.io/package/webmiddle.md) ^0.3.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2018-04-12
- 0.2.0 — 2017-04-27
- 0.1.1 — 2017-01-24
- 0.1.0 — 2017-01-21
- 0.0.1 — 2016-06-27

## README

# webmiddle-service-http-request 

> Service built on top of the [request](https://github.com/request/request) library, it is used to perform http requests.

## Install

```bash
npm install --save webmiddle-service-http-request
```

## Usage

```jsx
import { PropTypes, rootContext } from 'webmiddle';
import HttpRequest from 'webmiddle-service-http-request';

const MyService = () => (
  <HttpRequest
    name="rawHtml"
    contentType="text/html"
    url="https://news.ycombinator.com/"
  />
);

rootContext.evaluate(<MyService />)
.then(resource => {
  console.log(resource.content); // the html page as a string
});
```

## How it works

It uses the CookieManager for storing and retrieving cookies.

The **request body** can be specified either directly as a string or as
a JSON object, in the latter case it will be converted to a string by
the service.

The **body conversion** to string depends on the ‘Content-Type’ http
header, if it is set to “application/json”, then the body will be
JSON-stringified, otherwise the default
“application/x-www-form-urlencode” content type is assumed, thus the
body will be converted to form data.

The service resolves with the **response body** wrapped in a resource,
whose name and contentType must be specified as attributes.

If the contentType attribute is set to “application/json”, then the
content will be JSON-parsed, otherwise it will be kept as is.

In case of **http error**, the service fails with an **HttpError
object** containing the error status code.

The service uses the ErrorBoundary service to retry in case of
errors.
The amount of retries can be customized with the `networkRetries` context option.

## Properties

Name                   | Description
-----------------------|------------------------------------------------------
name                   | The name of the returned resource.
contentType            | The contentType of the returned resource
url                    | The url of the http request.
method (optional)      | The method of the http request, e.g. 'GET', 'POST'. Defaults to 'GET'.
body (optional)        | The body of the http request.
httpHeaders (optional) | Additional http headers to use in the http request.

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