HTTPie: How to Set a Timeout

Updated

Learn how to set a request timeout in the terminal using HTTPie

HTTPie: How to Set a Timeout

Before we start, make sure you have HTTPie installed on your computer. If you don't have it yet, you can install it with Homebrew:

brew install httpie

By default, HTTPie has no timeout at all, so it waits forever for a slow server. To set one, open your terminal and run this command:

http --timeout=5 https://example.com

Just replace https://example.com with your own URL. The --timeout flag takes the number of seconds to wait, and decimals work too, like --timeout=2.5. Put it before the URL.

If the server takes longer than that, HTTPie gives up and prints http: error: Request timed out (5.0s). If the server answers in time, you just get the normal response, so don't worry about setting it a little higher than you need.

Set a Default Timeout

To use a timeout on every request, add it to default_options in HTTPie's config file. On macOS and Linux it lives at ~/.config/httpie/config.json, and on Windows at %APPDATA%\httpie\config.json:

{
"default_options": [
"--timeout=10"
]
}

Now a plain http command uses that timeout without any flags.

undefined

If you need more time for one request, just pass --timeout on the command. It's added after the default options, so it wins.