| title | Gateway API Communication |
|---|---|
| description | Backend communication patterns and URL management for CLI commands |
| sidebar | API |
| icon | Globe |
The DeployStack Gateway CLI manages backend communication automatically through stored configuration and credential management. This guide covers how CLI commands interact with the backend and manage different environments.
When users authenticate with the gateway, the backend URL is automatically stored alongside their credentials. This eliminates the need to specify the backend URL for every command after initial login.
Storage Location:
- Primary: macOS Keychain, Windows Credential Manager, or Linux Secret Service
- Fallback: Encrypted file at
~/.deploystack/credentials.enc
The backend URL is stored as part of the StoredCredentials object and persists across CLI sessions.
CLI commands resolve the backend URL using this priority order:
- Command-line override -
--urlflag when provided - Stored URL - URL saved during authentication
- Default fallback -
https://cloud.deploystack.io
This approach supports both development workflows with local backends and production usage seamlessly.
The gateway automatically adapts behavior based on the backend URL:
Production Mode (https://cloud.deploystack.io):
- Strict HTTPS enforcement
- Full SSL certificate validation
- Standard error messages
Development Mode (localhost or custom URLs):
- HTTP connections allowed for localhost
- Development-specific error messages
- Additional debugging context
All API-dependent commands should verify authentication before making requests. The credential storage handles token validation and expiration checking automatically.
Commands should retrieve stored credentials and use the embedded backend URL rather than requiring URL parameters. The URL resolution pattern ensures consistency across all commands.
Different backend environments may return different error formats. Commands should handle both production and development error responses gracefully.
The API client accepts stored credentials and automatically extracts the appropriate backend URL. No additional URL configuration is required when credentials contain the backend information.
All authenticated requests include:
- Bearer token authentication
- User-Agent identification
- Content-Type specification
Network operations include appropriate timeouts with different values for various operation types:
- OAuth callback operations
- API requests
- Token refresh operations
Developers working with local backends can authenticate once and have all commands automatically use the development server:
The authentication flow stores the development URL, and subsequent commands use it automatically without additional configuration.
Commands maintain --url override options for testing different backends or switching environments temporarily without re-authentication.
To switch between environments, users can either:
- Re-authenticate with a different backend URL
- Use command-line URL overrides for temporary testing
Backend URLs are validated during authentication to ensure they meet security requirements for the target environment.
Each backend URL maintains separate credential storage, preventing credential leakage between development and production environments.
Production environments enforce HTTPS communication, while development environments allow HTTP for localhost testing.
Commands should provide helpful error messages that include the backend URL being used, especially for development environments where connectivity issues are common.
Token expiration and invalid token errors should guide users to re-authenticate, preserving their backend URL preference.
Different backend versions or configurations may return varying error formats. Commands should handle these gracefully and provide consistent user experience.
When developing new CLI commands that interact with the backend:
- Use the credential storage system for authentication
- Extract backend URL from stored credentials
- Implement URL override options for flexibility
- Handle environment-specific error cases
- Provide clear error messages with backend context
The DeployStack API client handles most backend communication complexity automatically. Commands should focus on business logic rather than HTTP details.
Test commands against both production and development backends to ensure consistent behavior across environments. The URL storage system supports this testing workflow naturally.