# simple-requests

> A library for performing simple http(s) requests.

Latest version **1.0.0-beta** (published 2022-10-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install simple-requests
pnpm add simple-requests
yarn add simple-requests
bun add simple-requests
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-beta |
| Published | 2022-10-02 |
| First published | 2020-05-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 19.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jason Favrod |
| Maintainers | jfavrod |
| Keywords | HTTP, HTTPS, REQUEST, SIMPLE, GET, PUT, POST, DELETE |

## Links

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

## Dependencies (1)

- [form-data](https://npm.io/package/form-data.md) ^3.0.0

## 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.0.0-beta (latest) — 2022-10-02
- 0.4.1 — 2022-06-30
- 0.4.0 — 2022-03-19
- 0.3.4 — 2021-05-24
- 0.3.3 — 2021-01-11
- 0.3.2 — 2021-01-11
- 0.3.1 — 2020-07-24
- 0.3.0 — 2020-06-26
- 0.2.3 — 2020-06-23
- 0.2.2 — 2020-06-17
- 0.2.1 — 2020-06-16
- 0.2.0 — 2020-06-16
- 0.1.1 — 2020-05-28
- 0.1.0 — 2020-05-28

## README

simple-requests
===============
A package for making simple HTTP requests (GET, POST, PUT, DELETE).

Installation
------------
```
npm install simple-requests
```

Use
---
### GET Request

**JavaScript**
```javascript
const { get } = require('simple-requests');

get('https://postman-echo.com/get?foo1=bar1&foo2=bar2')
.then((res) => console.log(res));
```

**TypeScript**
```typescript
import { get } from 'simple-requests';

(async () => {
    const res = await get('https://postman-echo.com/get?foo1=bar1&foo2=bar2')
    console.log(res);
})();
```

### Responses
`get` requests returns objects with the `IResponse` interface:

```typescript
interface IResponse {
    data: any;
    headers: http.IncomingHttpHeaders;
}
```

**Example Response**
```javascript
{
  headers: {
    date: 'Thu, 28 May 2020 04:20:44 GMT',
    'content-type': 'application/json; charset=utf-8',
    'content-length': '247',
    connection: 'close',
    etag: 'W/"f7-wONllpKRvpcZ0DGneUbLd5irmW0"',
    vary: 'Accept-Encoding',
    'set-cookie': [
      'sails.sid=s%3Ab_94okJLKIMCu8R20ZCVCvl1nZkXXc40.SqaDcfefqu6ZSDm%2FVuJ%2BZPsrjmXN1GHy%2FrzUyIpFxC0; Path=/; HttpOnly'
    ]
  },
  data: {
    args: { foo1: 'bar1', foo2: 'bar2' },
  }
}
```

**Error Response**
Error response default to unclassified error, or a JavaScript error message.

```javascript
{
  data: 'Unclassified error.',
  error: true,
  headers: {
    date: 'Thu, 28 May 2020 04:20:44 GMT',
    'content-type': 'text/plain; charset=utf-8',
    'content-length': '19'
  }
}
```

### POST Requests
`post` requests are similar to `get` requests, with the addition of a
`data` property to the `options` parameter.

__Note: more about `data` parameter, including examples, will be added.__

#### URL Encoded Form Data
Sending URL encoded form data.

```typescript
import querystring from 'querystring';

// Requesting an OAuth 2 bearer token.
  const data = querystring.stringify({
      client_id: this.clientId,
      client_secret: this.clientSecret,
      grant_type: 'client_credentials'
  });

  // Make sure to set the correct Content-Type.
  tmp = await post(this.oauthUrl, {
      data,
      headers: {
          'Content-length': data.length,
          'Content-type': 'application/x-www-form-urlencoded',
      }
  });

  console.log('token', tmp.data);
```

**Output**
```sh
# OAuth 2 bearer token.
zgBUCUQneGqAwz44ghwXe82i54CI
```

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