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

highwire

v1.1.6

Published

A high level HTTP client

Downloads

49

Readme

Highwire

High level HTTP methods that are easy to build upon.

Code Climate Test Coverage Issue Count Circle CI

Reasoning

Superagent is a fantastic module, but I find that I generally need to wrap it up for use in a more functional approach. Highwire provides this functional approach through simple HTTP methods that work great for building complex network layers, or just to make syncing your React components easier. They are meant to be wrapped in higher order functions to build complex network logic.

API

Highwire exposes an object with RESTful HTTP methods. Those methods are:

get(url [, options: { headers, query } ])

  • url: full url of request
  • options:
    • headers: object of headers to attatch to request
    • query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
    • timeout: cancel request after specified timeout (throws Error)
import { get } from 'highwire'
import { User } from './models'

const headers = { authorization: 'token <token>' }
const query = { sortOrder: 'desc' }
const timeout = 3000

get('/users', { headers, query, timeout })
  .then((response) => response.body)
  .then((body) => JSON.parse(body))
  .then((users) => console.log(users))
  .catch((err) => console.log(err))

post(url, data [, options: { headers, query } ])

  • url: full url of request
  • data: body to send with request
  • options:
    • headers: object of headers to attatch to request
    • query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
    • timeout: cancel request after specified timeout (throws Error)
    • progress: function that is called on progress event of request; returns: { direction: string, lengthComputable: boolean, loaded: number, total: number }
import { post } from 'highwire'
import { User } from './models'

const headers = { authorization: 'token <token>' }
const timeout = 3000
const progress = (event) => console.log(event.loaded))
const user = new User({ name: 'highwire' })

post('/users', user.toJSON(), { headers, timeout, progress })
  .then((response) => response.body)
  .then((body) => JSON.parse(body))
  .then((user) => console.log(user))
  .catch((err) => console.log(err))

put(url, data [, options: { headers, query } ])

  • url: full url of request
  • data: body to send with request
  • options:
    • headers: object of headers to attatch to request
    • query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
    • timeout: cancel request after specified timeout (throws Error)
import { put } from 'highwire'
import { User } from './models'

const headers = { authorization: 'token <token>' }
const timeout = 3000

User.find({ name: 'highwire' })
  .then((user) => user.addScope('some-action'))
  .then((user) => put(`/users/${user.id}`, user.toJSON(), { headers, timeout }))
  .then((response) => response.body)
  .then((body) => JSON.parse(body))
  .then((user) => console.log(user))
  .catch((err) => console.log(err))

patch(url, data [, options: { headers, query } ])

  • url: full url of request
  • data: body to send with request
  • options:
    • headers: object of headers to attatch to request
    • query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
    • timeout: cancel request after specified timeout (throws Error)
import { patch } from 'highwire'
import { User } from './models'

const headers = { authorization: 'token <token>' }
const timeout = 3000

User.find({ name: 'highwire' })
  .then((user) => user.addScope('some-action'))
  .then((user) => patch(`/users/${user.id}`, user.toJSON(), { headers, timeout }))
  .then((response) => response.body)
  .then((body) => JSON.parse(body))
  .then((user) => console.log(user))
  .catch((err) => console.log(err))

del(url, [, options: { headers, query } ])

  • url: full url of request
  • options:
    • headers: object of headers to attatch to request
    • query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
    • timeout: cancel request after specified timeout (throws Error)
import { del } from 'highwire'
import { User } from './models'

const headers = { authorization: 'token <token>' }
const timeout = 3000

User.find({ name: 'highwire' })
  .then((user) => del(`/users/${user.id}`, { headers, timeout }))
  .then(() => console.log('user deleted'))
  .catch((err) => console.log(err))

multipart(url, { meta: fields, attachments } [, options: { headers, query, progress }])

  • url: full url of request
  • meta:
    • fields[[name, value]] any form fields to attach to request
    • attachments[[name, path, filename]]: any attachments to attach to request
  • options:
    • headers: object of headers to attatch to request
    • query: object of query parameters to attach to request (DO NOT USE: if url contains query params)
    • timeout: cancel request after specified timeout (throws Error)
    • progress: function that is called on progress event of request; returns: { direction: string, lengthComputable: boolean, loaded: number, total: number }
const attachments = [
  ['profile', './tmp/profile.jpg'],
]
const progress = (event) => console.log(event)
const timeout = 5000

User.find({ name: 'highwire' })
  .then((user) =>
    multipart(
      `/users/${user.id}/profile`,
      { attachments },
      { progress, timeout },
    )
  .then((response) => JSON.parse(response.body))
  .then((data) => console.log(data))
  .catch((err) => console.log(err))