# api-request-simple

> Wraps the request module for simple REST api interfacing with predetermined hosts.

Latest version **1.3.1** (published 2018-03-03) · ISC license · 0 weekly downloads

## Install

```sh
npm install api-request-simple
pnpm add api-request-simple
yarn add api-request-simple
bun add api-request-simple
```

## 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.3.1 |
| Published | 2018-03-03 |
| First published | 2018-02-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | UladKasach |
| Maintainers | uladkasach |
| Keywords | request, api, http, https |

## Links

- npm: https://www.npmjs.com/package/api-request-simple
- Repository: https://github.com/uladkasach/api-request-simple
- Homepage: https://github.com/uladkasach/api-request-simple#readme
- Issues: https://github.com/uladkasach/api-request-simple/issues
- npm.io page: https://npm.io/package/api-request-simple

## 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.3.1 (latest) — 2018-03-03
- 1.2.2 — 2018-03-02
- 1.2.1 — 2018-03-01
- 1.0.1 — 2018-02-28
- 1.0.0 — 2018-02-28

## README

# api-request-simple

[![npm](https://img.shields.io/npm/v/api-request-simple.svg?style=flat-square)](https://www.npmjs.com/package/api-request-simple)
[![npm](https://img.shields.io/npm/dm/api-request-simple.svg)](https://www.npmjs.com/package/api-request-simple)

This module  wraps the request module for simple REST api interfacing with predetermined hosts

It is meant to be used in situations where you have a finite and predetermined set of hosts which you regularly interact with.  

# Example
In these cases
```js
var hosts = require("/config/hosts.json")
var api = new (require("api-request-simple"))(hosts)

var data = {foo : "bar"}
api.get("host_name", "/request/path/", data)
```

replaces

```js
var promise_request = require("require-promise");
var hosts = require("/config/hosts.json")
var data = {foo : "bar"}

// request queue id and trading id from api
var options = {
    method : 'GET',
    url: "http://" + hosts["host_name"] + "/request/path",
    json : true, // default to json
    qs : data, // convert "data" to qs
}
return promise_request(options);

```


and it particularly shines when you wish to use requests with client-certificates, where :

```js
var hosts = require(process.env.root+"/config/hosts.json");
var fs = require('fs');
var client_cert = {
    cert : fs.readFileSync(process.env.root+'/config/workhorse.pem'),
    key : fs.readFileSync(process.env.root+'/config/workhorse.key'),
    ca : fs.readFileSync(process.env.root+'/config/ca.pem'),
}
var api = new (require("api-request-simple"))({hosts:hosts, client_cert : client_cert });

var data = {foo : "bar"}
api.get("host_name", "/request/path/", data);
```


replaces

```js

var promise_request = require("require-promise");
var hosts = require(process.env.root+"/config/hosts.json");
var fs = require('fs');
var client_cert = {
    cert : fs.readFileSync(process.env.root+'/config/workhorse.pem'),
    key : fs.readFileSync(process.env.root+'/config/workhorse.key'),
    ca : fs.readFileSync(process.env.root+'/config/ca.pem'),
}

var options = {
    method : 'GET',
    url: "http://" + hosts["host_name"] + "/request/path",
    cert: client_cert.cert,
    key: client_cert.key,
    ca: client_cert.ca,
    qs : data, // convert "data" to qs
};
var promise_to_register = promise_request(options)
```

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