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
#!/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
}chmod +x .git/hooks/pre-pushWhat 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 Smokekeeps it to the fast checks. The full regression suite belongs in CI.--bailstops at the first failure: you only need one reason not to push.--quietprints 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):
requestarium run-collection "Users API" --folder Smoke --env Local --bail --quietlefthook:
pre-push:
commands:
api-smoke:
run: requestarium run-collection "Users API" --folder Smoke --env Local --bail --quietPlain 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:
command -v requestarium >/dev/null || exit 0A 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:
requestarium run-collection "Users API" --folder Smoke --env Local --env-file .env.local --bail --quietKeep 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 5000so 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.