Working with Environments
Environments in Maeris allow you to manage variables and configuration settings that can be reused across multiple API requests. This makes it easy to switch between different environments like development, staging, and production.
What are Environments?
Environments are containers for variables and settings that define the context in which your API requests run. They help you:
- Store reusable variables like base URLs, API keys, and tokens
- Switch between different environments (dev, staging, prod) easily
- Avoid hardcoding values in your requests
- Share configuration across team members
- Maintain separate configurations for different environments
Creating Environments
- Open Environment Settings: Navigate to your collection settings and find the Environments section
- Create New Environment: Click "New Environment" or "Add Environment"
- Name Your Environment: Give it a descriptive name like "Development", "Staging", or "Production"
- Add Variables: Define key-value pairs for your variables
Common variables include baseUrl, apiKey, token, userId, etc.
- Save Environment: Save your environment configuration
Using Variables in Requests
Once you've defined variables in an environment, you can use them in your API requests by referencing them with double curly braces.
Variable Syntax
Use {{variableName}} to reference a variable in:
- URL paths:
/api/users/{{userId}} - Headers:
Authorization: Bearer {{token}} - Request body:
{{email}} - Query parameters:
?page={{pageNumber}}
Example Environment Configuration
Here's an example of a Development environment configuration:
And a Production environment:
Switching Between Environments
You can easily switch between environments when running your API requests. This allows you to test the same requests against different environments without modifying the requests themselves.
- Select the active environment from the environment dropdown in your collection
- All variables from the selected environment will be used when running requests
- You can switch environments at any time without changing your request definitions
Best Practices
- Use Descriptive Names: Name your variables clearly (e.g., "baseUrl" instead of "url")
- Separate Secrets: Store sensitive information like API keys and tokens in environments, not in requests
- Use Consistent Naming: Use the same variable names across environments for consistency
- Document Variables: Add descriptions to help team members understand what each variable is for
- Version Control: Keep environment configurations in version control (excluding secrets)
- Use Default Values: Set default values for variables when possible
Shared Environments
You can share environments with your team members so everyone uses the same configuration. Shared environments ensure consistency across the team and make it easier to collaborate.
Note: When sharing environments, be careful with sensitive information. Consider using environment-specific secrets management for production credentials.
Next Steps
- API Collections and Organization - Learn about organizing your API tests
- API Flows – Chaining Multiple APIs - Use variables in chained requests
- API Assertions and Validations - Validate responses using variables