# manifetch

> A simple manifest-based fetch() API client building utility.

Latest version **0.0.3** (published 2021-11-04) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2021-11-04 |
| First published | 2021-04-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 38 |
| Maintainers | galvez |

## Links

- npm: https://www.npmjs.com/package/manifetch
- Repository: https://github.com/terixjs/manifetch
- Issues: https://github.com/terixjs/manifetch/issues
- npm.io page: https://npm.io/package/manifetch

## Recent versions

- 0.0.3 (latest) — 2021-11-04
- 0.0.2 — 2021-10-25
- 0.0.1 — 2021-04-30

## README

# manifetch

A simple manifest-based [`fetch()`](https://fetch.spec.whatwg.org/) API client building utility.

It is obvious in the sense it uses a staightforward, _**nearly obvious**_ pattern to **automatically build API clients from route definitions in a minimalist manifest**. Conceived originally as part of [`fastify-api`](https://github.com/galvez/fastify-api), which already provides a manifest compatible with `manifetch` based on your API route definitions.

## Install

```
$ npm i manifetch --save
```

## Usage

```js
const fetch = require('undici-fetch')
const manifetch = require('manifetch')

const prefix = 'https://jsonplaceholder.typicode.com'
const get = manifetch({ fetch, prefix })

const manifest = {
  getPosts: ['GET', '/posts'],
  getPost: ['GET', '/posts/:id'],
  nestedDemonstration: {
    getPosts: ['GET', '/posts'],
    getPost: ['GET', '/posts/:id'],  
  },
}

const client = new Proxy(manifest, { get })

async function main () {
  const { json: posts } = await client.getPosts()
  const { json: post } = await client.getPost({ id: 10 })
  console.log('First post out of collection:', posts[0])
  console.log('Tenth post, individually requested', post)
}

main().then(() => process.exit())
```

See also [example][example] and [test][test].

[example]: https://github.com/terixjs/manifetch/blob/main/example.js
[test]: https://github.com/terixjs/manifetch/blob/main/test.js

## Goals

- [ ] **Work seamlessly** on **Node**, **Deno** and **on the browser**
- [x] Facilitate `fetch()` usage with **minor**, **sensible API enhancements**
- [x] **Automatically** construct API clients based on a **minimalist API manifest**
- [ ] Support both a **minimalist manifest** and the **OpenAPI specification** 

## Status

- [x] Basic Node implementation using [undici-fetch][uf] for `fetch()`
- [ ] Write comprehensive test suite based on [node-tap](https://node-tap.org/).
- [ ] Write comprehensive usage examples for [`fastify-api`][fa] and [`fastify-vite`][fv]
- [ ] Optimize `applyParams()` implementation with new **fast-apply-params** package
- [ ] Memoize `Proxy` instances on the client, prepopulate all wrappers on the server

[fa]: https://github.com/galvez/fastify-api
[fv]: https://github.com/galvez/fastify-vite
[uf]: https://github.com/Ethan-Arrowood/undici-fetch

## License

MIT

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