Run API smoke tests before every git push

CI catches a broken endpoint ten minutes after you push. A pre-push hook catches it before the push leaves your machine. Keep it to a fast smoke folder against your local API, and it costs a few seconds.

The hook

.git/hooks/pre-push
#!/bin/sh
# Run the API smoke tests against the local API before pushing.

if ! curl -fs http://localhost:8080/health >/dev/null; then
  echo "pre-push: local API isn't running, skipping API smoke tests."
  exit 0
fi

requestarium run-collection "Users API" --folder Smoke --env Local --bail --quiet || {
  echo ""
  echo "pre-push: API smoke tests failed. Fix them, or push anyway with: git push --no-verify"
  exit 1
}
Terminal
chmod +x .git/hooks/pre-push

What each part is for:

  • The health check skips the tests when your API isn't running, so a hook doesn't block a docs-only push from a laptop with nothing started.
  • --folder Smoke keeps it to the fast checks. The full regression suite belongs in CI.
  • --bail stops at the first failure: you only need one reason not to push.
  • --quiet prints only failures and the summary.

The hook uses your own requestarium login, so there's no token to set up. It needs the CLI installed globally (npm install -g @requestarium/cli).

Share it with the team

.git/hooks isn't committed. To share the hook, use whatever your repository already uses for hooks.

Husky (JavaScript projects):

.husky/pre-push
requestarium run-collection "Users API" --folder Smoke --env Local --bail --quiet

lefthook:

lefthook.yml
pre-push:
  commands:
    api-smoke:
      run: requestarium run-collection "Users API" --folder Smoke --env Local --bail --quiet

Plain git, committed: put the script in scripts/git-hooks/pre-push and have each developer run git config core.hooksPath scripts/git-hooks once.

For people who don't have the CLI or don't use Requestarium, make the hook skip itself:

Terminal
command -v requestarium >/dev/null || exit 0

A Local environment everyone has

The hook runs --env Local, so every developer needs an environment with that name pointing at their local API. Create it once in the shared workspace with baseUrl set to http://localhost:8080; people who run the API on another port can override it in their own copy, or the hook can pass --var baseUrl=….

If the smoke tests need secrets, keep them out of the environment and in a local, ignored .env file:

Terminal
requestarium run-collection "Users API" --folder Smoke --env Local --env-file .env.local --bail --quiet

Keep it fast

A hook people skip every time is worse than no hook. Aim for under ten seconds:

  • Only read-only requests and one or two writes that clean up after themselves.
  • No --iterations, no data files, no --delay.
  • Use --timeout 5000 so a hung request doesn't hang the push.

If the smoke folder grows past that, move requests to Regression and let CI run them.

Pre-push or pre-commit?

Pre-push. Commits happen often and locally; running the API tests on each one is too much. A push is the moment your code leaves your machine, which is where a quick check is worth its seconds.