HTTPie: How to Use Basic Auth

Updated

Learn how to authenticate API requests with Basic Auth in HTTPie

HTTPie: How to Use Basic Auth

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

brew install httpie

Pass Basic Auth Credentials

To use Basic Authentication in HTTPie, pass the -a (or --auth) flag followed by your username:password pair. Basic auth is HTTPie's default, so you don't need to pass --auth-type=basic:

http -a username:password GET https://example.com/api/data

Just swap username:password and https://example.com/api/data with your own credentials and endpoint.

Common Variations

To keep your password out of your shell history, omit it and let HTTPie prompt you securely:

http -a username GET https://example.com/api/data

If your account uses an empty password, include a trailing colon like -a username: so HTTPie skips the prompt. You can also embed credentials inline in the URL with https://username:password@example.com/api/data, though -a takes priority if you pass both.

undefined

To avoid re-entering credentials on every request, save them to a named session with --session=my_session on the first call, then drop -a on future requests.