# @teclone/xhr

> Exports list of industry categories, reusable for web project implementation

Latest version **1.0.0** (published 2020-03-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @teclone/xhr
pnpm add @teclone/xhr
yarn add @teclone/xhr
bun add @teclone/xhr
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-03-02 |
| First published | 2020-03-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 126 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Harrison Ifeanyichukwu |
| Maintainers | teclone |

## Links

- npm: https://www.npmjs.com/package/@teclone/xhr
- Repository: https://github.com/teclone/xhr
- Homepage: https://github.com/teclone/xhr#readme
- Issues: https://github.com/teclone/xhr/issues
- npm.io page: https://npm.io/package/@teclone/xhr

## Dependencies (1)

- [@teclone/utils](https://npm.io/package/@teclone/utils.md) 2.15.0

## Recent versions

- 1.0.0 (latest) — 2020-03-02

## README

# Xhr

[![Build Status](https://travis-ci.org/teclone/xhr.svg?branch=master)](https://travis-ci.org/teclone/xhr)
[![Coverage Status](https://coveralls.io/repos/github/teclone/xhr/badge.svg?branch=master)](https://coveralls.io/github/teclone/xhr?branch=master)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![npm version](https://badge.fury.io/js/%40teclone%2Fxhr.svg)](https://badge.fury.io/js/%40teclone%2Fxhr)
![npm](https://img.shields.io/npm/dt/%40teclone%2Fxhr.svg)

Fetch API compatible implementation in XMLHttpRequest. Fully promisified. Works in browser like environments, including React Native.

## Installation

module is available on npm

```bash
npm install @teclone/xhr
```

## Usage

There are method names for all of these six http methods `get`, `head`, `options`, `post`, `delete`, `put` that you can use to make requests.
By default, the request will never throw even on errors (unlike the Fetch api spec). You need to check the **ok** property of the response object.

This can be changed by setting `options.throwIfNotOk` to `true` or by calling `Xhr.throwIfNotOk(true)` to set this for every request. The value of `throwIfNotOk` in ecah **request options** will always be prioritized ahead of the global settings.

```typescript
import { Xhr } from '@teclone/xhr';

Xhr.get(url, options).then(response => {
  if (response.ok) {
    // do something.
  }
});
```

## Running in Mocked Browser Environments

To make it seemless when you want to run in mocked browser environment, **Xhr** module exports `install` method to make this possible. Call the `install` method, passing in the window and document object.

**Running in jsdom environment:**

```javascript
import JSDOM from 'jsdom';
import { Xhr } from '@teclone/xhr';

const dom = new JSDOM('<!doctype html><html><body></body></html>', {
  url: 'urltomock',
  pretendToBeVisual: true,
});

Xhr.install(dom.window, dom.window.document);
```

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