npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fitch

v0.11.0

Published

A lightweight Promise based HTTP client, using Fetch API.

Downloads

32

Readme

Fitch.js

Fitch.js

A lightweight Promise based HTTP client, using Fetch API.

npm version Build Status Documentation Status license

bitHound Overall Score bitHound Dependencies bitHound Code Gitter

Features

  • Uses Fetch API
  • Works on both old and new browsers and on Node.js
  • Supports the Promise API
  • Transform request and response data
  • Automatic transforms for JSON data

Get started

Install

npm i --save fitch

Use

With ES2015 or TypeScript:

import fitch from 'fitch'

CommonJS:

const fitch = require('fitch')

CDN:

unpkg

<script src="https://unpkg.com/fitch/dist/index.umd.min.js"></script>

jsDelivr

<script src="https://cdn.jsdelivr.net/g/fitch.js"></script>

Make your first request:

fitch.get(apiUrl)
  .then(response => console.log(response))

/* Response:
{
  data: { foo: 'bar' },
  status: 200,
  statusText: 'Ok',
  headers: { Content-Type: application/json },
}
*/

Methods available:

get

fitch.get(apiUrl)
  .then(response => console.log(response))

post

const req = {body: {name: 'Happy cat'}}

fitch.post(apiUrl, req)
  .then(response => console.log(response))

put

const req = {body: {name: 'Happy cat'}}

fitch.put(apiUrl, req)
  .then(response => console.log(response))

patch

const req = {body: {name: 'Happy cat'}}

fitch.patch(apiUrl, req)
  .then(response => console.log(response))

del

fitch.del(apiUrl)
  .then(response => console.log(response))

Use with custom configuration

const config = {
  cache = 'no-store',
  headers = { 'Content-Type': 'application/json' },
  mode = 'no-cors',
  params: { // transform to '?test1=test-1&test2=test-2'
    test1: 'test-1',
    test2: 'test-2',
  },
  raw = true, // return the raw output of fetch()
  redirect: 'follow',
}

fitch.get(apiUrl, config)
  .then(response => console.log(response))

See more about fetch configuration at: Fetch API.

Concurrency

all

Helper function for dealing with concurrent requests.

const reqDogs = fitch.get('/dogs')
const reqCats = fitch.get('/cats')

function doSomething([ responseDogs, responseCats ]) {
  console.log('Dogs\t>>>', responseDogs)
  console.log('Cats\t>>>', responseCats)
}

fitch.all([ reqDogs, reqCats ])
  .then(doSomething)

Default Configuration and Request Interceptor

const fetchWrapper = fitch.init({
  config: { raw: true },
  interceptor: response => response.json(),
})

fetchWrapper.get(baseUrl).then(data =>
  console.log('GET with interceptor\t>>>', data)
)

Browser Support

  • Chrome
  • Firefox
  • Edge
  • Safari 6.1+
  • Internet Explorer 10+

Note: modern browsers such as Chrome, Firefox, and Microsoft Edge contain native implementations of window.fetch, so the polyfill doesn't have any affect on those browsers. See more at window.fetch polyfill.

Contributig

Read the Code of conduct.

First yout need to fork this repository. Then:

yarn # install local dependencies
yarn start # run local server
yarn watch:test # watch files inside src/ and tests/
yarn build # run examples
yarn examples # run examples

Note: Your code must be tested and pass in linter check. You can verify your code with ESLint, using npm run lint.

Logo

Copyright © Bárbara Schoen