Overview
This endpoint demonstrates KrakenD’s static response (mocking) capability. It returns a predefined JSON response without calling any backend service, useful for testing, development, and API prototyping. HTTP Method:GETEndpoint:
/mocked-response
What It Demonstrates
- Static Responses: Returns hardcoded data without backend calls
- API Mocking: Simulates API responses during development
- Testing Support: Provides predictable responses for testing
- Backend Decoupling: Allows frontend development before backend completion
Request Example
Expected Response
Status:200 OK
Backend Configuration
Although a backend is configured, it is never called:- Host:
http://unexistent_backend(non-existent host) - URL Pattern:
/ - Purpose: Placeholder (required by configuration but unused due to static response)
KrakenD Configuration
Key Configuration Options
proxy.static
Configures static response behavior:
Static Data (data)
- Primitives (strings, numbers, booleans, null)
- Arrays
- Nested objects
- Any valid JSON structure
Strategy (strategy)
always- Always return the static response, never call the backendsuccess- Return static response on backend successcomplete- Return static response only when backend completeserrored- Return static response when backend fails (fallback)
always:
- Backend is never called
- Response is instant (no network latency)
- Backend host can be non-existent
- Perfect for pure mocking
Output Encoding
json.
Use Cases
1. API Development
Define API contracts before backend implementation:2. Testing
Provide predictable responses for automated tests:3. Frontend Development
Allow frontend teams to work independently:- No backend required
- Consistent test data
- Fast iteration cycles
4. API Documentation
Provide live examples in documentation:5. Feature Flags
Temporarily return static data during migrations:6. Fallback Responses
Return static data when backends fail:Strategy Comparison
| Strategy | When Static Response is Returned |
|---|---|
always | Always (backend never called) |
success | When backend call succeeds |
complete | When backend call completes (success or failure) |
errored | When backend call fails |
Performance
Response Time
Mocked endpoint:- Response time: < 1ms
- No network overhead
- No backend processing
- Response time: 50-500ms (typical)
- Network latency
- Backend processing time
Load Testing
Mocked endpoints can handle extremely high throughput:Advanced Patterns
Dynamic-Like Responses
While the response is static, you can make it appear dynamic:Conditional Mocking
Combine with request matching for conditional mocking:Large Responses
You can mock large datasets:Limitations
Static Data Only
- Cannot include dynamic values (timestamps, random numbers, etc.)
- Same response for every request
- Cannot vary based on request parameters
No Backend Validation
- Request validation must be handled elsewhere
- Cannot verify request payloads
- No real business logic execution
Configuration Size
Very large static responses can bloat the configuration file. Consider using external files for large datasets.Transitioning to Real Backend
When the backend is ready, transition is simple: Before (Mocked):proxy.static configuration and update the backend host.
Testing the Endpoint
Basic Test
Verify Response Structure
Check Response Time
Verify No Backend Calls
The backend host (http://unexistent_backend) doesn’t exist, proving no backend is called:
Best Practices
- Use for Development: Enable mocking during development, disable in production
- Document Clearly: Mark mocked endpoints in your API documentation
- Match Real Structure: Make mocked responses identical to real backend responses
- Version Control: Keep static data in version control
- Transition Plan: Plan how to transition from mocked to real backends
- Use Realistic Data: Use realistic sample data for better testing