# request-agent

> ## Install

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

## Install

```sh
npm install request-agent
pnpm add request-agent
yarn add request-agent
bun add request-agent
```

## 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.1.0 |
| Published | 2018-04-03 |
| First published | 2016-06-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | lanhao |
| Maintainers | lanhao |

## Links

- npm: https://www.npmjs.com/package/request-agent
- npm.io page: https://npm.io/package/request-agent

## Dependencies (1)

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

## Recent versions

- 1.1.0 (latest) — 2018-04-03
- 1.0.3 — 2016-06-14
- 1.0.2-b — 2016-06-08

## README

#  ES6 Promise-base http request agent 

## Install 

    npm install request-agent --save

## Init httpAgent

    const requestAgent = require('request-agent');

## Configure your http-request entity

### 0. An example

    requestAgent.headers({'content-type':'application/json'})
        .headers({ 'user-agent':'customer UA' , 'power-by':'lanhao@fyscu' })
        
        .query({ 'page':1 , 'pageSize':10 })
        .query({ '_t':1465317270 })
        
        .body({ 'title':'I say' , 'content':'Nothing' })
        
        .method('post')
        
        .send()
        
        .then(requestAgent.toJson)  // this step is optional 
        
        .then( (obj) => {
            //do something
            console.log(obj);
        })
        
        .catch( (err) => {
            //error handler
            console.trace(err);
        });

### 1.http headers

    requestAgent.headers({'content-type':'application/json'}  [ ,flush=false ])         
   
  setting multi-headers in 2 ways:
        
    requestAgent.headers({'content-type':'application/json','UA':'MyAgent'})    
  or
        
    requestAgent.headers({'content-type':'application/json'}).headers({'UA':'MyAgent'})
    
  Parameter `flush` , default false ,told the request-agent clear the old headers or not.
  
### 2.http query string

    requestAgent.query({'_t':1441089765}  [ ,flush=false ])    
       
  some like `headers` .
   
### 3.http body

    requestAgent.body({'content':'I send this message to server'}  [ ,flush=false ])    
       
  some like `headers` .
  
### 4. Not Finished

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