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

Related tags

Command Line cli http
Overview

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"

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]
  --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]
  --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.
You might also like...

Pipeable javascript. Quickly filter, map, and reduce from the terminal

Pipeable JavaScript - another utility like sed/awk/wc... but with JS! Quickly filter, map and reduce from the command line. Features a streaming API.

Dec 10, 2022

Kill all Chrome tabs to improve performance, decrease battery usage, and save memory

Kill all Chrome tabs to improve performance, decrease battery usage, and save memory

kill-tabs Kill all Chrome tabs to improve performance, decrease battery usage, and save memory Works on macOS, Linux, Windows. I'm a tab-abuser and I

Jan 8, 2023

📜 Create mutable log lines into the terminal, and give life to your logs!

📜 Create mutable log lines into the terminal, and give life to your logs!

Because Logging can be pretty and fun Installation $ npm install draftlog What it does It allows you to re-write a line of your log after being writt

Dec 31, 2022

HMSC (How Much Stuffs CLI) analyst for your files and folders

HMSC (How Much Stuffs CLI) analyst for your files and folders

HMSC 🔰 About HMSC (How Much Stuffs CLI) analyst for your files and folders 📸 Screenshot 📓 Requirements Node.js NPM 🔌 Installation $ npm i -g hmsc

Jan 10, 2022

Add a hungry turtle to your terminal and feed it every time you mistype 'npm' as 'nom'

Add a hungry turtle to your terminal and feed it every time you mistype 'npm' as 'nom'

Nom Does this ever happen to you? You happily code away on a project, navigating the command line like a pro, testing, error logging, installing packa

Apr 26, 2022

replacement for comma.ai backend and useradmin dashboard. comes bundled with a modified cabana instance for seamless drive reviewing.

replacement for comma.ai backend and useradmin dashboard. comes bundled with a modified cabana instance for seamless drive reviewing.

retropilot-server Replacement for comma.ai backend and useradmin dashboard. Bundled with a modified version of comma's cabana to allow viewing & analy

Dec 4, 2022

Tasks Management CLI application with Nodejs, Mongodb, inquirer.js, and commander

Tasks CLI Tasks CLI is a program to manage your tasks in a database using terminal or console. This is a sample project for beginners Requirements Nod

Nov 17, 2022

A simple CLI tool to create and manage xhelpers-api projects

A simple CLI tool to create and manage xhelpers-api projects

Feb 25, 2022

A fullstack(NestJS、React) framework for building efficient and scalable applications

A fullstack(NestJS、React) framework for building efficient and scalable applications

A fullstack(NestJS、React) framework for building efficient and scalable applications. Description The Kunlun CLI is a command-line interface tool that

Mar 12, 2022
Comments
  • Add Headers option to allow request headers to be set

    Add Headers option to allow request headers to be set

    Adds support for providing request headers as part of the got request.

    Use-case - testing a URL that expects certain headers to be present before returning the expected response. Allows more specific testing.

    released 
    opened by LMulvey 1
  • The automated release is failing 🚨

    The automated release is failing 🚨

    :rotating_light: The automated release from the main branch failed. :rotating_light:

    I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

    You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this 💪.

    Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

    Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

    If you are not sure how to resolve this, here are some links that can help you:

    If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


    No npm token specified.

    An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

    Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


    Good luck with your project ✨

    Your semantic-release bot :package::rocket:

    semantic-release 
    opened by github-actions[bot] 0
  • feat: docker support

    feat: docker support

    This add a Dockerfile to provide this as a docker image.

    This will probably need some extra from your end if you want to publish this to Dockerhub as then an addition could be made to the README.md.

    Final Docker Image size:

    179MB - 175MB of that is node:16-slim

    Reasons for specific things in the Dockerfile:

    1. Why npm install --production instead of npm ci in 'productionDependencies' stage.

    A comparison with the size of node_modules from npm ci vs npm install --production:

    | Command | Size of node_modules | | ---- | --- | | npm ci | 250M | | npm install --production | 4.7M |

    Can check with docker run -it --entrypoint=/bin/bash waitehr:ci if you build with making the changes to the Dockerfile to use the different commands

    1. Why tini and what for?

    This is for proper handling of signals. Without tini the yargs command doesnt terminate correctly. I think it would be possible to have proper handling of signals but might be a more significant code change.

    With tini the listening for SIGINT works as expected.

    opened by zogot 0
Owner
Gajus Kuizinas
Software architect. Passionate about JavaScript, React, GraphQL, Redux. Active open-source contributor.
Gajus Kuizinas
a simple zero-configuration command-line http server

http-server: a command-line http server http-server is a simple, zero-configuration command-line http server. It is powerful enough for production usa

http ... PARTY! 12.4k Jan 4, 2023
A simple development http server with live reload capability.

Live Server This is a little development server with live reload capability. Use it for hacking your HTML/JavaScript/CSS files, but not for deploying

Tapio Vierros 4k Dec 31, 2022
Started pack for working with the new GameTest Framework API. Usable in windows, and mobile in worlds and realms!

GameTest FrameWork GameTest FrameWork is a new feature in Minecraft Bedrock Edition. This gives you the ability to script! In this example I will be u

null 40 Dec 24, 2022
A CLI to add and remove local development environments and create HTTPS certificates for them.

A CLI used to create a local https dev environment with the green lock. Setup takes less than 5 minutes and all of your projects will be running locally over HTTPS with custom domain names in no time!

Entrostat (Pty) Ltd 5 Sep 19, 2022
Find and fix problems in your JavaScript code.

ESLint Website | Configuring | Rules | Contributing | Reporting Bugs | Code of Conduct | Twitter | Mailing List | Chat Room ESLint is a tool for ident

ESLint 22k Jan 8, 2023
Infinite Red's cutting edge React Native project boilerplate, along with a CLI, component/model generators, and more!

Ignite - the hottest React Native boilerplate Battle-tested React Native boilerplate The culmination of five years of constant React Native developmen

Infinite Red, Inc. 14.7k Dec 29, 2022
Test your internet connection speed and ping using speedtest.net from the CLI

speed-test Test your internet connection speed and ping using speedtest.net from the CLI Install Ensure you have Node.js version 8+ installed. Then ru

Sindre Sorhus 3.8k Jan 7, 2023
Detect copy-pasted and structurally similar code

Detect copy-pasted and structurally similar JavaScript code. Requires Node.js 6.0+, and supports ES6, JSX as well as Flow. Note: the project has been

Daniel St. Jules 3.5k Dec 26, 2022
Move files and directories to the trash

Move files and folders to the trash Works on macOS (10.12+), Linux, and Windows (8+). Note: The Linux implementation is not very good and not maintain

Sindre Sorhus 2.4k Dec 29, 2022