Environment Basics
Environments in KnoxCall allow you to manage different configurations (dev, staging, production) for the same route without duplicating everything.What is an Environment?
An environment is a configuration context that determines which settings to use for a route. Think of it as a profile or mode.Real-World Analogy
Imagine a light switch with multiple modes:- “Day” mode → Bright lights, full power
- “Night” mode → Dim lights, low power
- “Movie” mode → Colored lights, ambient
- Production → Real API keys, production database
- Staging → Test API keys, staging database
- Development → Mock data, local server
Why Use Environments?
The Problem Without Environments
Without environments, you’d need separate routes for each stage:- Duplicate routes to maintain
- Easy to misconfigure
- Hard to keep in sync
- Route names get messy
The Solution With Environments
With environments, you have one route with different configs:- Single route to maintain
- Consistent naming
- Easy to switch between environments
- Clear separation of configs
How Environments Work
The Base + Override System
KnoxCall uses a base + override system:- Base environment - Default configuration
- Override environments - Customize specific settings
- If override =
nullor empty → Use base value - If override = specific value → Use override value
- Changes to base automatically affect overrides (unless overridden)
Default Environments
KnoxCall creates one default environment for every tenant:Production (Base Environment)
- Name:
production - Type: Base
- Purpose: Default configuration
- Usage: If no environment specified, this is used
Common Environment Setup
Typical 3-Environment Setup
Most teams use three environments:1. Development
- Purpose: Local development and testing
- Target:
http://localhost:3000or sandbox APIs - Secrets: Test/fake API keys
- Clients: Developer laptops (dynamic IPs)
- Example:
2. Staging
- Purpose: Pre-production testing
- Target: Staging servers
- Secrets: Staging API keys (real-ish data)
- Clients: Staging servers + QA team
- Example:
3. Production
- Purpose: Live customer traffic
- Target: Production servers
- Secrets: Production API keys (real data!)
- Clients: Production servers only
- Example:
Using Environments in Requests
Specify Environment with Header
To use a specific environment, add the header:No Header = Base Environment
If you don’t specifyx-knoxcall-environment, KnoxCall uses the base environment (usually production).
What Can Be Overridden?
You can override almost everything per environment:✅ Can Override
| Setting | Example |
|---|---|
| Target URL | https://api.production.com vs https://localhost:3000 |
| Headers | Different API keys, auth tokens |
| Body | Different payload structures |
| Secrets | Production vs test secrets |
| Clients | Production servers vs dev laptops |
| Rate limits | Higher limits in prod, lower in dev |
| Method configs | Different per HTTP method |
❌ Cannot Override
| Setting | Reason |
|---|---|
| Route name | Would create confusion |
| Enabled/disabled | Applies to all environments |
| HTTP methods allowed | Security concern |
Real-World Examples
Example 1: Stripe API Route
Scenario: Process payments via Stripe in all environments. Setup:- Production charges real cards with prod key
- Staging/dev use test keys (no real charges)
- Different client authorization per environment
Example 2: Database API
Scenario: Query user database across environments. Setup:- Each environment hits a completely different database
- Developers work with local data
- Staging has realistic test data
- Production has real customer data
Example 3: Third-Party Webhooks
Scenario: Receive webhooks from Shopify. Setup:- Production webhooks go to production backend
- Staging webhooks go to staging
- Dev webhooks tunnel to developer’s localhost via ngrok
NULL Values = Inherit
This is a key concept: NULL or empty values inherit from the base.Example
- Target URL:
https://api.production.com(inherited) - Header:
Bearer staging_key(overridden)
Best Practices
✅ Do
1. Use descriptive environment names❌ Don’t
1. Don’t use production secrets in devWhen to Create New Environments
Create New Environments When:
-
Different target systems
- Production API vs staging API vs local dev
-
Different credentials
- Production keys vs test keys
-
Different authorization
- Production servers vs developer laptops
-
Different teams
- QA environment separate from dev
-
Different regions
- US environment vs EU environment
Don’t Create Environments For:
- Different features - Use different routes instead
- Different customers - Use route parameters or headers
- Different versions - Use API versioning in URLs
- Temporary testing - Use staging environment
Environment Workflows
Development Workflow
Environment Promotion
Troubleshooting
Environment Not Found
Error:- Go to Resources → Environments
- Check if “staging” exists
- Create it if missing
- Verify spelling (case-sensitive)
Using Wrong Environment
Symptom: Request goes to wrong backend. Solution:- Check
x-knoxcall-environmentheader value - Verify environment name spelling
- Check which environment your route is configured for
Override Not Working
Symptom: Still using base configuration despite override. Cause: Override value isnull (inheritance).
Solution:
- Edit route → Environment Overrides
- Set specific value (not null)
- Save changes
Quick Reference
| Concept | Explanation |
|---|---|
| Environment | Configuration context (dev, staging, prod) |
| Base Environment | Default configuration (usually production) |
| Override | Environment-specific customization |
| Inheritance | NULL/empty values use base configuration |
| Switching | Use x-knoxcall-environment header |
Next Steps
Environment Workflows
Advanced environment patterns
Rate Limiting
Per-environment rate limits
First Environment
Create your first environment
Managing Secrets
Environment-specific secrets
Key Takeaway: Environments let you manage dev, staging, and production with one route instead of three. Override only what’s different, inherit the rest!