# relaxful

> A REST API client. Currently no file upload support.

Latest version **1.0.4** (published 2018-02-16) · 0 weekly downloads

## Install

```sh
npm install relaxful
pnpm add relaxful
yarn add relaxful
bun add relaxful
```

## 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.0.4 |
| Published | 2018-02-16 |
| First published | 2017-09-28 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Ian Foose |
| Maintainers | ianfoose |
| Keywords | API, restful, API Client, REST |

## Links

- npm: https://www.npmjs.com/package/relaxful
- Repository: https://github.com/ianfoose/relaxful-node-js
- Homepage: https://github.com/ianfoose/relaxful-node-js#readme
- Issues: https://github.com/ianfoose/relaxful-node-js/issues
- npm.io page: https://npm.io/package/relaxful

## Dependencies (1)

- [url](https://npm.io/package/url.md) ^0.11.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.4 (latest) — 2018-02-16
- 1.0.3 — 2018-02-09
- 1.0.2 — 2017-10-25
- 1.0.1 — 2017-09-28
- 1.0.0 — 2017-09-28

## README

# Relaxful Node-js

A REST API client.  Currently no file upload support.

## Use

Note the path to the APIHelper.js module, if not installed through npm or a package manager use the absolute path the the file.

Non npm ```require('./relaxful.js');```

### Simple Request

Access string result using 'result.text' property of the result object if request is successfule

Also supports https  

```js
var helper = require('relaxful');

helper.request('get', 'http://someurl/some/path').promise.then(result => {
  console.log(result.text);
}).catch(error => {
  // todo handle error
});
```

### Request Headers

```js
var helper = require('relaxful');

var reqHeaders = { 'api-key': 'some-api-key' };

helper.request('get', 'http://someurl/some/path',{ headers: reqHeaders }).promise.then(result => {
  console.log(result.text);
}).catch(error => {
  // todo handle error
});
```

### Request Body

```js

var helper = require('relaxful');

var body = { 'name': 'John Smith' };

helper.request('get', 'http://someurl/some/path', { body: body }).promise.then(result => {
  console.log(result.text);
}).catch(error => {
  // todo handle error
});
```

### JSON

Use the 'json()' method of a result to parse JSON data from the reqponse.

```js
var helper = require('relaxful');

helper.request('get', 'http://someurl/some/path').promise.then(result => {
  return result.json();
}).then(json => {
  // todo handle json object  
}).catch(error => {
  // todo handle error
});
```

### Validation

Use the 'validate()' method of a result to validate its' status code.

```js
var helper = require('./relaxful');

helper.request('get', 'http://someurl/some/path').promise.then(result => {
  return result.validate();
}).then(result => {
  console.log(result.text); 
}).catch(error => {
  // todo handle error
});
```

### Response

When a response fails validation or you need to check the HTTP Status code, you can access the ```status``` property of the response.  To get the HTTP Status message, access it through the ```message``` property.  

```js
var helper = require('./relaxful');

helper.request('get', 'http://someurl/some/path').promise.then(result => {
  return result.validate();
}).then(result => {
  console.log(result.status); 
  console.log(result.message);
}).catch(error => {
  // todo handle error
});     
```

To access a plain text response of the response body, use the ```text``` property.

```js
var helper = require('./relaxful');

helper.request('get', 'http://someurl/some/path').promise.then(result => {
  return result.text;
}).catch(error => {
  // todo handle error
});
```

Response headers are passed back in the ```headers``` property of the response.  

```js
var helper = require('./relaxful');

helper.request('get', 'http://someurl/some/path').promise.then(result => {
  return result.headers;
}).catch(error => {
  // todo handle error
});
```

### Cancel a Request

The current request is stored in the 'req' property of the helper object.  
Get the current helper object and access the request property and abort.

```js
helper.req.abort();
```

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