# @dnpr/make-request

> A simple HTTP/HTTPS agent for Node.js.

Latest version **1.0.0** (published 2020-01-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @dnpr/make-request
pnpm add @dnpr/make-request
yarn add @dnpr/make-request
bun add @dnpr/make-request
```

## 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 |
| Published | 2020-01-14 |
| First published | 2019-07-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 27.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | dragonman225 |
| Maintainers | dragonman225 |

## Links

- npm: https://www.npmjs.com/package/@dnpr/make-request
- Repository: https://github.com/dnpr/make-request
- Issues: https://github.com/dnpr/make-request/issues
- npm.io page: https://npm.io/package/@dnpr/make-request

## Recent versions

- 1.0.0 (latest) — 2020-01-14
- 0.1.1 — 2019-10-30
- 0.1.0 — 2019-07-02

## README

# make-request

A simple HTTP / HTTPS agent for Node.js.

## Documentation

* [Installation](#Installation)
* [Usage](#Usage)
* [Development](#Development)

## Installation

```bash
npm install @dnpr/make-request
```

## Usage

```typescript
import { makeRequest } from "@dnpr/make-request"

const httpTarget = "http://httpbin.org"
const httpsTarget = "https://httpbin.org"
const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"

async function main() {

  const headers = {
    "accept": "*/*",
    "accept-encoding": "gzip, deflate, br",
    "accept-language": "en-US,en;q=0.9",
    "user-agent": USER_AGENT
  }

  const testBody = {
    message: "hello world"
  }

  try {

    /** A GET request with HTTP. */
    const testHttp = makeRequest("GET", httpTarget + "/get")()
    console.log((await testHttp).data.toString())

    /** A GET request with HTTPS. */
    const testHttps = makeRequest("GET", httpsTarget + "/get")()
    console.log((await testHttps).data.toString())

    /** A GET request with HTTPS and headers. */
    const testHttpsHeader =
      makeRequest("GET", httpsTarget + "/get")
        .useHeaders(headers)()
    console.log((await testHttpsHeader).data.toString())

    /** A POST request with JSON. */
    const testJson =
      makeRequest("POST", "https://reqbin.com/echo/post/json")
        .useSerializer(JSON.stringify)
        .useDeserializer(JSON.parse)({
          login: "login", password: "password"
        })
    console.log((await testJson).data)

    /** A bad POST request with incorrectly serialized body. */
    const testBadJson =
      makeRequest("POST", "https://reqbin.com/echo/post/json")(testBody)
    console.log((await testBadJson).data)

  } catch (error) {
    console.error(error)
  }
}

main()
```

## Development

### Project Structure

![project structure graph](documentation/dependency-graph.svg)

### Setup

```bash
git clone https://github.com/dnpr/make-request.git
yarn install
```

### Run tests

```bash
npm test
```

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