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

@devnetic/fetch

v1.0.1

Published

The Fetch package provides an interface for fetching resources (including across the network).

Downloads

4

Readme

fetch

npm (scoped) npm bundle size (scoped) npm GitHub issues GitHub

The Fetch package provides an interface for fetching resources (including across the network).

This package it's a wrapper around http|https Node.js native packages.

Usage

GET

fetch('https://jsonplaceholder.typicode.com/posts')
  .then(response => {
    console.log(response.json())
  })
  .catch(error => {
    console.log(error)
  })

POST

fetch('https://jsonplaceholder.typicode.com/posts', {
  method: 'POST',
  body: JSON.stringify({
    title: 'foo',
    body: 'bar',
    userId: 1
  }),
  headers: {
    "Content-type": "application/json; charset=UTF-8"
  }
})
  .then(response => response.json())
  .then(json => console.log(json))
  .catch(error => {
    console.log(error)
  })

PUT

fetch('https://jsonplaceholder.typicode.com/posts/1', {
  method: 'PUT',
  body: JSON.stringify({
    id: 1,
    title: 'foo',
    body: 'bar',
    userId: 1
  }),
  headers: {
    "Content-type": "application/json; charset=UTF-8"
  }
})
  .then(response => response.json())
  .then(json => console.log(json))
  .catch(error => {
    console.log(error)
  })

PATCH

fetch('https://jsonplaceholder.typicode.com/posts/1', {
  method: 'PATCH',
  body: JSON.stringify({
    title: 'foo'
  }),
  headers: {
    "Content-type": "application/json; charset=UTF-8"
  }
})
  .then(response => response.json())
  .then(json => console.log(json))
  .catch(error => {
    console.log(error)
  })

DELETE

fetch('https://jsonplaceholder.typicode.com/posts/1', {
  method: 'DELETE'
})
  .then(response => response.json())
  .then(json => console.log(json))
  .catch(error => {
    console.log(error)
  })

Parameters

  • url <string|URL>
  • init <Object>
    • agent <http.Agent|boolean> Controls Agent behavior. Possible values:
      • undefined (default): use http.globalAgent for this host and port.
      • Agent object: explicitly use the passed in Agent.
      • false: causes a new Agent with default values to be used.
    • auth <string> Basic authentication i.e. 'user:password' to compute an Authorization header.
    • createConnection <Function> A function that produces a socket/stream to use for the request when the agent option is not used. This can be used to avoid creating a custom Agent class just to override the default createConnection function. See agent.createConnection() for more details. Any Duplex stream is a valid return value.
    • defaultPort <number> Default port for the protocol. Default: agent.defaultPort if an Agent is used, else undefined.
    • family <number> IP address family to use when resolving host or hostname. Valid values are 4 or 6. When unspecified, both IP v4 and v6 will be used.
    • headers An object containing request headers.
    • host <string> A domain name or IP address of the server to issue the request to. Default: 'localhost'.
    • hostname <string> Alias for host. To support url.parse(), hostname will be used if both host and hostname are specified.
    • localAddress <string> Local interface to bind for network connections.
    • method <string> A string specifying the HTTP request method. Default: 'GET'.
    • path <string> Request path. Should include query string if any. E.G. 'index.html?age=12'. An exception is thrown when the request path contains illegal characters. Currently, only spaces are rejected but that may change in the future. Default: '/'.
    • port <number> Port of remote server. Default: defaultPort if set, else 80.
    • protocol <string> Protocol to use. Default: 'http:'.
    • setHost Specifies whether or not to automatically add the Host header. Defaults to true.
    • socketPath <string> Unix Domain Socket (cannot be used if one of host or port is specified, those specify a TCP Socket).
    • timeout <number> A number specifying the socket timeout in milliseconds. This will set the timeout before the socket is connected.