# @tpapp/use-http

> React hooks for async axios calls

Latest version **1.0.2** (published 2021-10-12) · GNU license · 0 weekly downloads

## Install

```sh
npm install @tpapp/use-http
pnpm add @tpapp/use-http
yarn add @tpapp/use-http
bun add @tpapp/use-http
```

## 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.2 |
| Published | 2021-10-12 |
| First published | 2021-10-12 |
| Weekly downloads | 0 |
| License | GNU |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 53.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Thomas Papp |
| Maintainers | tpapp |

## Links

- npm: https://www.npmjs.com/package/@tpapp/use-http
- Repository: https://github.com/ThomasPapp/use-http
- Homepage: https://github.com/ThomasPapp/use-http#readme
- Issues: https://github.com/ThomasPapp/use-http/issues
- npm.io page: https://npm.io/package/@tpapp/use-http

## Dependencies (2)

- [@types/axios](https://npm.io/package/@types/axios.md) ^0.14.0
- [@types/react](https://npm.io/package/@types/react.md) ^17.0.11

## Recent versions

- 1.0.2 (latest) — 2021-10-12

## README

# use-http
React hook for async axios calls

### Example:
```js
const { loading, success, error, runHttpGet } = useHttp()
...
try {
    // the run http functions return a promise containing any data sent from the endpoint
    const data = await runHttpGet("/api/some_endpoint")
    ...
} catch (e) {
    // An error occurred, handle error responses here
    // Any non-successful http status codes get caught here too
}
```

### Available hook fields
The `useHttp` hook returns the following data which can be destructured 
```ts
interface HttpHook {
    loading: boolean,
    success: boolean,
    error: object | null,
    cancel: () => void,
    runHttpGet: (url: string) => Promise<any>,
    runHttpPost: (url: string, body: object) => Promise<any>,
    runHttpPut: (url: string, body: object) => Promise<any>,
    runHttpDelete: (url: string) => Promise<any>
}
```

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