examples Variables and auth
auth_command.http
Command-backed auth from gh auth token, with file defaults, named definitions with use=, @apply reuse, JSON output and custom headers. The mycli request needs a CLI of your own.
needs a GitHub token
resterm _examples/auth_command.httpRun this from the root of a clone of the Resterm repository.
Editor
Command-backed auth docs### File Command Auth Default
# @auth file command cmd="gh auth token" cache_key=github-cli-file
### Named Command Auth
# @auth file command name=gh cmd="gh auth token"
### Reusable Command Auth Profile
# @patch file githubCliAuth {auth: {type: "command", argv: '["gh","auth","token"]', cache_key: "github-cli"}}
### GitHub CLI Token Via File Auth
# @name GitHubCLITokenFile
# @tag auth command file
# @description Inherits command-backed bearer auth from the file-scoped @auth directive above.
GET https://api.github.com/user
Accept: application/vnd.github+json
X-GitHub-Api-Version: 2022-11-28
### GitHub CLI Token Via Named Auth
# @name GitHubCLITokenNamed
# @tag auth command
# @description Runs the gh definition above once per environment and reuses its token.
# @auth use=gh
GET https://api.github.com/user
Accept: application/vnd.github+json
X-GitHub-Api-Version: 2022-11-28
### Named Auth In A Custom Header
# @name GitHubCLITokenNamedHeader
# @tag auth command
# @description Sends the same cached gh token as a raw value in a custom header.
# @auth use=gh header=X-GitHub-Token
GET https://api.github.com/rate_limit
Accept: application/json
### GitHub CLI Token Via @apply
# @name GitHubCLITokenPatched
# @tag auth command
# @description Reuses command-backed bearer auth through a file-scoped apply profile.
# @apply use=githubCliAuth
GET https://api.github.com/user
Accept: application/vnd.github+json
X-GitHub-Api-Version: 2022-11-28
### GitHub CLI Token
# @name GitHubCLIToken
# @tag auth command
# @description Uses the GitHub CLI token printer. Run `gh auth login` outside Resterm first.
# @auth command argv=["gh","auth","token"] cache_key=github-cli
GET https://api.github.com/user
Accept: application/vnd.github+json
X-GitHub-Api-Version: 2022-11-28
### GitHub CLI Token Reuse
# @name GitHubCLITokenReuse
# @tag auth command
# @description Reuses the github-cli command auth slot and can also seed it on a cold start.
# @auth command argv=["gh","auth","token"] cache_key=github-cli
GET https://api.github.com/user/repos
Accept: application/vnd.github+json
X-GitHub-Api-Version: 2022-11-28
### Structured JSON Output
# @name CommandJSONToken
# @tag auth command
# @description Parses token, token type, and expiry fields from JSON stdout.
# @auth command argv=["mycli","auth","print","--json"] format=json token_path=access_token type_path=token_type expires_in_path=expires_in cache_key=myapi
GET https://api.github.com/user
Accept: application/json
### Custom Header Injection
# @name CommandCustomHeader
# @tag auth command
# @description Sends a raw token to a custom header instead of Authorization.
# @auth command argv=["gh","auth","token"] header=X-GitHub-Token cache_key=github-cli-custom-header ttl=10m
GET https://api.github.com/rate_limit
Accept: application/json
### Fixed Scheme Override
# @name CommandFixedScheme
# @tag auth command
# @description Overrides token_type with a fixed scheme string.
# @auth command argv=["gh","auth","token"] header=Authorization scheme=Token cache_key=github-cli-custom-scheme
GET https://api.github.com/user
Accept: application/json