# ajax-request

> Http request for nodejs, and it also support file download

Latest version **1.2.3** (published 2017-06-27) · ISC license · 0 weekly downloads

## Install

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

## 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.2.3 |
| Published | 2017-06-27 |
| First published | 2014-11-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 31 |
| Author | douzi |
| Maintainers | douzi |
| Keywords | request, http, ajax, http, request, http download, image, json, resource, download, file download, base64, image base64 |

## Links

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

## Dependencies (2)

- [file-system](https://npm.io/package/file-system.md) ^2.1.1
- [utils-extend](https://npm.io/package/utils-extend.md) ^1.0.7

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.2.3 (latest) — 2017-06-27
- 1.2.2 — 2017-05-27
- 1.2.1 — 2015-04-09
- 1.2.0 — 2015-03-25
- 1.1.0 — 2015-01-29
- 1.0.7 — 2015-01-14
- 1.0.6 — 2014-12-05
- 1.0.5 — 2014-12-04
- 1.0.4 — 2014-12-04
- 1.0.3 — 2014-12-04
- 1.0.1 — 2014-12-03
- 1.0.0 — 2014-11-28

## README

# ajax-request — Simplified http request
[![NPM](https://nodei.co/npm/ajax-request.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/ajax-request/)
```js
var request = require('ajax-request');
```

## install
```
npm install ajax-request --save
```

### test
```
mocha
```

## API
### request(options, callback)
* {obejct|string} ``options`` required  
  If the options is string, it will send get request.
  * {string} ``options.url`` required
  * {string} ``options.method`` [options.method=GET]  
  The http request type
  * {obejct} ``options.data``  
  if the request type is `GET`, it's appended to query string of the URL, or it's sended to remote of body.
  * {object} ``options.headers``  
  An object containing request headers.
  * {string} ``options.encoding``  
  Set response data encoding
  * {boolean} ``options.isBuffer``  [options.isBuffer=false]  
  Parse response data to buffer
  * {boolean} ``options.json`` [options.json=false]  
  Parse response data to json
* {function} ``callback`` required

```js
request('url', function(err, res, body) {});

request({
  url: '',
  method: 'GET',
  data: {
    query1: 'value1'
  }
}, function(err, res, body) {
  
});
```

### .post(options, callback)
The API same as request
```js
request.post({
  url: 'url',
  data: {},
  headers: {}
});
```

### .download(options, callback)
* {obejct} ``options`` required
  * ``options.url`` {string} required
  * ``options.ignore`` {boolean} [options.ignore=false]  
  Is the filepath ignore case. 
  * ``options.rootPath`` {string} [options.rootPath='']  
  The root of dest path
  * ``options.destPath`` {string|function}  
  Custom the download path.
* {function} ``callback`` required

```js
request.download({
  url: 'path/index.png',
  rootPath: ''
}, function(err, res, body, destpath) {});

request.download({
  url: 'path/index.png',
  destPath: function(filename) {
    return filename;
  }
}, function(err, res, body, destpath) { });

```

### .base64(url, callback)
Deprecated, move to [base64](https://github.com/douzi8/base64-img#requestbase64url-callback)

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