New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

manifetch

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

manifetch

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

latest
Source
npmnpm
Version
0.0.3
Version published
Weekly downloads
10
150%
Maintainers
1
Weekly downloads
 
Created
Source

manifetch

A simple manifest-based fetch() 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, which already provides a manifest compatible with manifetch based on your API route definitions.

Install

$ npm i manifetch --save

Usage

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 and test.

Goals

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

Status

  • Basic Node implementation using undici-fetch for fetch()
  • Write comprehensive test suite based on node-tap.
  • Write comprehensive usage examples for fastify-api and fastify-vite
  • Optimize applyParams() implementation with new fast-apply-params package
  • Memoize Proxy instances on the client, prepopulate all wrappers on the server

License

MIT

FAQs

Package last updated on 04 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts