HTTPie: How to Use Sessions

Updated

Learn how to persist cookies, auth, and headers across requests with HTTPie sessions

HTTPie: How to Use Sessions

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

Named Sessions

To persist cookies, authentication, and custom headers across multiple requests to the same host, pass the --session flag with a simple name on your first request:

http --session=user1 -a username:password example.org/profile API-Key:123

On subsequent requests, just pass --session=user1 again and HTTPie automatically sends your saved cookies, credentials, and headers:

http --session=user1 example.org/profile

Custom File Paths and Read-Only Sessions

If you want to keep a session file inside a specific project folder, pass a file path instead of a name:

http --session=./my-session.json POST example.org/login user=admin
http --session=./my-session.json GET example.org/dashboard

To reuse saved credentials and cookies without letting new server responses overwrite the file, use --session-read-only:

http --session-read-only=user1 example.org/data
undefined

HTTPie saves cookies, auth, and custom headers while skipping request-specific headers starting with Content- or If-. Named sessions live as plain-text JSON in ~/.config/httpie/sessions/, so avoid committing them to version control.