Bash

cURL GET with Timeout + Retry

admin by @admin ADMIN
5d ago
May 31, 2026
Public
0 0 up · 0 down Sign in to vote
A sensible default cURL invocation: short connect timeout, total timeout, retry on transient failures with backoff, fail-on-error.
Bash
Raw
curl -fsSL \
    --connect-timeout 10 \
    --max-time 30 \
    --retry 5 \
    --retry-delay 1 \
    --retry-max-time 60 \
    --retry-connrefused \
    -H "User-Agent: myapp/1.0" \
    "https://api.example.com/users"

# What each flag does:
#   -f / --fail        : exit non-zero on HTTP 4xx/5xx (otherwise prints error body)
#   -s / --silent      : no progress bar
#   -S                 : but still print errors
#   -L                 : follow redirects
#   --retry 5          : retry up to 5 times
#   --retry-delay 1    : 1s, 2s, 4s, 8s, ... between retries
#   --retry-connrefused: retry even on connection refused (default only on 5xx)
Tags

Save your own code snippets

Create a free account and build your private vault. Share publicly whenever you want.