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

waitehr

v1.11.0

Published

Waits for HTTP response and retries request until the expected response is received.

Downloads

148

Readme

Waits for expected HTTP response

Canonical Code Style Twitter Follow

waitehr (wait [for] expected HTTP response) is a CLI program that waits for HTTP response and retries request until the expected response is received.

Motivation

We needed a reliable utility for checking when a deployment goes live in a CI/CD pipeline.

Why not just use Bash/curl/...?

You should be able to do this with curl and a simple bash script.

You could achieve something similar to this with bash:

while curl https://gajus.com/ | grep -q Gajus; do sleep 1; done

However, by the time you add:

  • routine timeout
  • request timeout
  • follow redirects
  • max redirects
  • success threshold

It is going to be a pretty hefty script, and if everyone (with their varying experience of using Bash) were to write that script adhoc, it is likely to be error prone. It is for this reason that it makes sense to use a well tested utility that does it well.

Install

npm install waitehr --global

Usage

waitehr <url> [options]

# Waits for response with status code 200.
waitehr https://gajus.com/

# Retries request at most once every 5 seconds (default: 1).
waitehr https://gajus.com/ --interval 5

# Waits at most 120 seconds (default: 60).
waitehr https://gajus.com/ --timeout 60

# Waits for response with status code 200 or 404.
waitehr https://gajus.com/ --status-code 200 404

# Waits for response that contains "foo" and "bar".
waitehr https://gajus.com/ --contains "foo" "bar"

# Waits for response that has a specific header.
waitehr https://gajus.com/ --has-header "foo: bar"

# Adds custom headers to the request.
waitehr https://gajus.com/ --header "Accepts: text/html" "Authorization: Bearer
fkd9afsda9k"


Options:
  --help               Show help                                       [boolean]
  --version            Show version number                             [boolean]
  --contains           Expected string(s). If multiple strings are provided,
                       then all of them must be contained in the response.
                                                                         [array]
  --follow-redirect    Defines if redirect responses should be followed
                       automatically.                                  [boolean]
  --has-header         Expected header(s). If multiple headers are provided,
                       then all of them must be contained in the response.
                                                                         [array]
  --header             Extra header to include in the request when sending HTTP
                       to a server. <Header Key>: <Header Value>.        [array]
  --initial-delay      How many seconds to delay the first request.
                                                           [number] [default: 0]
  --interval           How many seconds to sleep between every attempt.
                                                           [number] [default: 1]
  --max-redirects      If exceeded, the request will be aborted.
                                                           [number] [default: 5]
  --prepend-time       Prepends time to each check output.
                                                       [boolean] [default: true]
  --quiet              Disables any output.           [boolean] [default: false]
  --request-timeout    How many seconds to wait for individual requests to
                       complete. If exceeded, requests are aborted and a new
                       request is started.                 [number] [default: 5]
  --status-codes       Expected status code(s). If multiple status codes are
                       provided, then either will be accepted as valid.
                                                        [array] [default: "200"]
  --success-threshold  Minimum consecutive successes for the probe to be
                       considered successful.              [number] [default: 1]
  --timeout            How many seconds to wait before giving up.  [default: 60]

Alternatives

  • check_http – Nagios plugin with equivalent functionality.
  • httping – utility for measuring latency and throughput of a webserver with limited some assertion capabilities.