Step 5: Response Configuration
Response Configuration defines how your API responds to requests, including success responses, error handling, response headers, and data transformation.
Overview
The Response Configuration step allows you to:
Configure success and error response formats
Set up response headers and status codes
Transform and filter response data
Customize response metadata
Response Formats
Success Responses
Basic Success Response
{
"success": true,
"data": {
"id": "sub_12345",
"name": "John Doe",
"email": "john@example.com",
"rating": 5,
"feedback": "Great product!",
"submitted_at": "2024-01-15T10:30:00Z"
},
"message": "Feedback submitted successfully"
}Minimal Success Response
{
"success": true,
"id": "sub_12345",
"message": "Feedback submitted successfully"
}Detailed Success Response
{
"success": true,
"data": {
"id": "sub_12345",
"name": "John Doe",
"email": "john@example.com",
"rating": 5,
"feedback": "Great product!",
"submitted_at": "2024-01-15T10:30:00Z",
"processed_at": "2024-01-15T10:30:01Z",
"status": "processed"
},
"metadata": {
"version": "1.0",
"request_id": "req_abc123",
"processing_time": "150ms"
},
"message": "Feedback submitted successfully"
}Error Responses
Validation Error Response
{
"success": false,
"error": {
"code": "VALIDATION_ERROR",
"message": "One or more fields failed validation",
"details": [
{
"field": "email",
"message": "Please enter a valid email address",
"code": "INVALID_EMAIL"
},
{
"field": "rating",
"message": "Rating must be between 1 and 5",
"code": "INVALID_RANGE"
}
]
},
"request_id": "req_abc123"
}Server Error Response
{
"success": false,
"error": {
"code": "INTERNAL_SERVER_ERROR",
"message": "An unexpected error occurred",
"request_id": "req_abc123",
"timestamp": "2024-01-15T10:30:00Z"
}
}Rate Limit Error Response
{
"success": false,
"error": {
"code": "RATE_LIMIT_EXCEEDED",
"message": "Too many requests. Please try again later.",
"retry_after": 60,
"limit": 100,
"remaining": 0,
"reset_time": "2024-01-15T11:00:00Z"
}
}HTTP Status Codes
Success Status Codes
200 OK
Standard successful response
Used for most successful operations
Includes response data
201 Created
Resource successfully created
Used for new submissions
Includes created resource data
202 Accepted
Request accepted for processing
Used for asynchronous operations
May not include final result
Error Status Codes
400 Bad Request
Invalid request format
Missing required fields
Malformed data
401 Unauthorized
Missing or invalid authentication
Expired tokens
Insufficient permissions
422 Unprocessable Entity
Validation errors
Business logic violations
Data format issues
429 Too Many Requests
Rate limit exceeded
Too many requests from same IP
API quota exceeded
500 Internal Server Error
Unexpected server errors
Database connection issues
System failures
Response Headers
Standard Headers
Content-Type
Content-Type: application/json; charset=utf-8CORS Headers
Access-Control-Allow-Origin: https://your-frontend.com
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Allow-Credentials: trueCache Control
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0Custom Headers
API Version
X-API-Version: 1.0
X-API-Deprecated: falseRequest Tracking
X-Request-ID: req_abc123
X-Response-Time: 150ms
X-Processing-Time: 120msRate Limiting
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1642248000Data Transformation
Output Formatting
Date Formatting
// Input: "2024-01-15T10:30:00Z"
// Output: "2024-01-15 10:30:00"
{
"field": "submitted_at",
"format": "YYYY-MM-DD HH:mm:ss"
}
// Input: "2024-01-15T10:30:00Z"
// Output: "January 15, 2024"
{
"field": "submitted_at",
"format": "MMMM DD, YYYY"
}Number Formatting
// Input: 1234.56
// Output: "1,234.56"
{
"field": "price",
"format": "currency",
"currency": "USD"
}
// Input: 1234.56
// Output: "1,234.56"
{
"field": "rating",
"format": "decimal",
"decimalPlaces": 2
}Text Processing
// Input: " John Doe "
// Output: "John Doe"
{
"field": "name",
"format": "trim"
}
// Input: "john@example.com"
// Output: "j***@example.com"
{
"field": "email",
"format": "mask",
"maskChar": "*",
"visibleChars": 1
}Field Filtering
Include/Exclude Fields
// Include only specific fields
{
"include": ["id", "name", "email", "submitted_at"]
}
// Exclude sensitive fields
{
"exclude": ["password", "ssn", "credit_card"]
}
// Conditional inclusion
{
"conditional": {
"include": ["admin_notes"],
"condition": {
"field": "user_role",
"operator": "equals",
"value": "admin"
}
}
}Nested Field Filtering
// Filter nested objects
{
"include": {
"user": ["id", "name", "email"],
"metadata": ["created_at", "updated_at"]
}
}Computed Fields
Calculated Fields
// Add computed field
{
"computed": {
"field": "days_since_submission",
"formula": "current_date - submitted_at",
"type": "number"
}
}
// Add status field
{
"computed": {
"field": "status",
"formula": "rating >= 4 ? 'positive' : 'negative'",
"type": "string"
}
}Aggregated Fields
// Add count field
{
"computed": {
"field": "total_submissions",
"formula": "count(*)",
"type": "number"
}
}
// Add average field
{
"computed": {
"field": "average_rating",
"formula": "avg(rating)",
"type": "number",
"decimalPlaces": 2
}
}Response Templates
Template Variables
System Variables
{
"variables": {
"timestamp": "{{current_timestamp}}",
"request_id": "{{request_id}}",
"api_version": "{{api_version}}",
"processing_time": "{{processing_time}}"
}
}Field Variables
{
"variables": {
"user_name": "{{name}}",
"user_email": "{{email}}",
"submission_id": "{{id}}",
"submission_date": "{{submitted_at}}"
}
}Template Examples
Email Confirmation Template
{
"success": true,
"data": {
"id": "{{id}}",
"name": "{{name}}",
"email": "{{email}}",
"submitted_at": "{{submitted_at}}"
},
"message": "Thank you {{name}}! Your feedback has been submitted successfully.",
"confirmation": {
"email_sent": true,
"email_address": "{{email}}",
"confirmation_id": "{{confirmation_id}}"
}
}Admin Notification Template
{
"success": true,
"data": {
"id": "{{id}}",
"name": "{{name}}",
"email": "{{email}}",
"rating": "{{rating}}",
"feedback": "{{feedback}}",
"submitted_at": "{{submitted_at}}"
},
"admin_notification": {
"sent": true,
"recipients": ["admin@company.com"],
"priority": "{{rating >= 4 ? 'low' : 'high'}}"
}
}Error Handling
Error Response Configuration
Error Message Templates
{
"error_templates": {
"validation_error": "Please check the following fields: {{error_fields}}",
"server_error": "We're experiencing technical difficulties. Please try again later.",
"rate_limit_error": "Too many requests. Please wait {{retry_after}} seconds before trying again."
}
}Error Logging
{
"error_logging": {
"enabled": true,
"level": "error",
"include_request_data": true,
"include_user_data": false,
"external_service": "sentry"
}
}Error Recovery
Retry Logic
{
"retry_config": {
"max_retries": 3,
"retry_delay": 1000,
"backoff_multiplier": 2,
"retryable_errors": ["timeout", "connection_error"]
}
}Fallback Responses
{
"fallback": {
"enabled": true,
"response": {
"success": false,
"error": {
"code": "SERVICE_UNAVAILABLE",
"message": "Service temporarily unavailable. Please try again later."
}
}
}
}Performance Optimization
Response Caching
Cache Configuration
{
"caching": {
"enabled": true,
"ttl": 300,
"cache_key": "{{endpoint_id}}_{{user_id}}",
"invalidate_on": ["update", "delete"]
}
}Cache Headers
Cache-Control: public, max-age=300
ETag: "abc123"
Last-Modified: Wed, 15 Jan 2024 10:30:00 GMTResponse Compression
Compression Settings
{
"compression": {
"enabled": true,
"algorithm": "gzip",
"min_size": 1024,
"content_types": ["application/json", "text/html"]
}
}Testing Response Configuration
Test Cases
Success Response Test
curl -X POST https://your-api.com/endpoint/user-feedback \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com",
"rating": 5,
"feedback": "Great product!"
}'Error Response Test
curl -X POST https://your-api.com/endpoint/user-feedback \
-H "Content-Type: application/json" \
-d '{
"name": "",
"email": "invalid-email",
"rating": 6
}'Response Validation
Schema Validation
{
"response_schema": {
"type": "object",
"required": ["success", "data"],
"properties": {
"success": { "type": "boolean" },
"data": { "type": "object" },
"message": { "type": "string" },
"metadata": { "type": "object" }
}
}
}Next Steps
After configuring response settings:
- Test and Deploy → Step 6: Testing & Deployment
Related Topics
Validation Rules - Data validation and business logic
Form Integration - Connecting forms to your API
API Reference - Complete API documentation