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

hitter

v0.0.10

Published

A simple library for hit requests

Downloads

7

Readme

Hitter

npm version build status Coverage Status npm downloads

A small library with zero dependencies for doing request hits (that is, requests in where you don't expect a response from the server). This library will try different methods, via Image, XHR or sendBeacon to get there, depending on availability and options passed.

Why?

The main use for this is when you want to do hits to an analytics endpoint, where you just want a reliable and fast way to send something and you don't care about the response.

That's why this library will try first using a Image request, and if the payload is too long, then with sendBeacon and XMLHttpRequest (if supported).

Although with XMLHttpRequest and sendBeacon will use a POST method, it will still send the payload as a query param string on plain text.

Installation

npm install hitter

Support

It should work on IE11+. Only for browser.

Example

Since this is thought to be a library to hit usually a unique endpoint, you pass a url to the constructor where you will get the hits. That way you can call many times the instance with different payloads.

var Hitter = require('hitter');
var hit = Hitter('//myapi.com/data');
// or var hit = require('hitter')('//myapi.com/data');

hit(
  {
    payload: {
      data1: 'value1',
      data2: 2,
    },
  },
  function() {
    // Do something after the request is sent
    // Not guaranteed that the request has finished
  }
);

Creating an instance

Hitter(baseUrl)

What you get from the library is a constructor that will take a url as a parameter that will be the base of where to do the calls (can be expanded with paths on the config options later at the instance level).

It will return a function that can be called to do the hits.

Using the instance

hit(config, callback?)

Will take a config object and an optional callback to do something after the hit (you won't get any parameters).

hit(callback?)

Optionally you can also call it with only an optional callback if you don't care about the config options.

Config object

All parameters are optional.

Config.force

Forces a specific method to call on. Possible values are beacon, img and xhr.

Config.path

Takes an array of strings that will as a path to the base url.

Config.payload

The payload to send along the request. It can be either a string or an object where the key/values will be translated to query parameters.

Config.maxImgLength

The max length of the query params to do an Image request. Defaults to 2036.