# fetch-repository

> A fetch wrapper with repository pattern register

Latest version **1.0.1-alpha.1** (published 2020-08-25) · ISC license · 0 weekly downloads

## Install

```sh
npm install fetch-repository
pnpm add fetch-repository
yarn add fetch-repository
bun add fetch-repository
```

## 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.1-alpha.1 |
| Published | 2020-08-25 |
| First published | 2020-08-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | diogolessa |

## Links

- npm: https://www.npmjs.com/package/fetch-repository
- npm.io page: https://npm.io/package/fetch-repository

## Recent versions

- 1.0.1-alpha.1 (latest) — 2020-08-25
- 1.0.1-alpha.0 — 2020-08-18

## README

# Fetch Repository

This is a simple library that consists in a fetch wrapper + repository pattern utility. You can use both together or in isolation.

**Warning: This is a fresh idea that is evolving, and may contain bugs.**

1. [Using the Fetch Wrapper](#using-the-fetch-wrapper)
2. [Using the Repository API](#using-the-repository-api)

### Using the fetch wrapper

```jsx
import { http } from 'fetch-repository'

// With promise
http
  .get(url, config)
  .then(result => {})
  .catch(err => {})

// With async/await
async function getData() {
  try {
    const result = await http.get(url, config)
  } catch (e) {
    console.error(e)
  }
}
```

### Using the repository api

```jsx
import { http, Repository } from 'fetch-repository'

Repository.add('Posts', {
  get baseUrl() {
    return 'https://jsonplaceholder.typicode.com/posts'
  },
  getAll() {
    return http.get(this.baseUrl)
  },
  getById(id: number) {
    return http.get(`${this.baseUrl}/${id}`)
  },
  create(body: object) {
    return http.post(this.baseUrl, body)
  },
})
```

Then, just consume it later:

```jsx
import { Repository } from 'fetch-repository'

const PostsRepository = Repository.get('Posts')

try {
  const posts = await PostsRepository.getAll()
} catch (e) {
  console.error(e)
}
```

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