PostResponder Service
Overview
The PostResponder is a lightweight Azure Function microservice that serves as a generic HTTP request handler and logger. This service acts as a simple endpoint that receives HTTP requests, validates basic parameters, logs the request details, and returns a standardized response format. It's primarily used for testing, debugging, and basic request tracking purposes.
Business Purpose
This service serves as a utility component in the Publisher ecosystem that: - Provides a generic HTTP endpoint for request testing and validation - Logs incoming requests for debugging and monitoring purposes - Returns standardized response formats for integration testing - Supports health check and probe functionality - Acts as a simple request/response validator for development workflows
Architecture
Service Type
- Platform: Azure Functions (Containerized Kubernetes Microservice)
- Runtime: Node.js
- Trigger: HTTP Trigger (Anonymous authentication)
- Pattern: Simple Request-Response Handler
Key Components
graph TD
A[HTTP Request] --> B[PostResponder]
B --> C[Query String Parser]
C --> D[Handler.js]
D --> E{Probe Request?}
E -->|Yes| F[Health Check Response]
E -->|No| G[Request Validation]
G --> H{Valid Request?}
H -->|Yes| I[Log Request Details]
H -->|No| J[Error Response]
I --> K[Generate Event Record]
K --> L[Success Response]
J --> M[Error Event Record]
L --> N[HTTP Response]
M --> N
F --> N
O[Application Insights] --> I
P[Logger] --> I
API Specification
Endpoint
- Method: GET/POST
- Authentication: Anonymous
- Content-Type: application/json
Request Parameters
Query Parameters
type(required): Request type identifierprobe(optional): Health check flag (boolean)
Request Validation
The service validates that incoming requests contain the required type parameter in the query string.
Response Format
Success Response
{
"status": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"event": {
"recordid": "generated-32-char-id",
"timestamp": 1640995200,
"status": "SUCCESS",
"statusCode": 200,
"errors": [],
"request": {
"query": {
"type": "request-type"
},
"url": "request-url",
"method": "GET|POST"
}
}
}
}
Error Response
{
"status": 500,
"headers": {
"Content-Type": "application/json"
},
"body": {
"event": {
"recordid": "generated-32-char-id",
"timestamp": 1640995200,
"status": "ERROR",
"statusCode": 500,
"errors": ["Request did not contain required data"]
}
}
}
Health Check Response (Probe)
{
"query": {
"probe": true
},
"url": "request-url",
"method": "GET"
}
Core Functionality
Request Processing
- Query String Parsing: Extracts and parses query parameters from the request URL
- Health Check Handling: Responds to probe requests for service health monitoring
- Request Validation: Validates that required parameters are present
- Request Logging: Logs complete request details for debugging and monitoring
- Response Generation: Creates standardized response format with unique tracking ID
Key Features
- Simple Request Validation: Basic validation of required query parameters
- Comprehensive Logging: Detailed logging of all incoming requests
- Unique Request Tracking: Generates unique record ID for each request
- Health Check Support: Built-in probe endpoint for monitoring
- Error Handling: Graceful error handling with detailed error messages
- Standardized Responses: Consistent response format across all operations
Request Flow
Normal Request Processing
- Request Reception: Receives HTTP request with query parameters
- Parameter Extraction: Parses query string and extracts parameters
- Validation: Checks for required
typeparameter - Logging: Logs request details with unique record ID
- Response: Returns success response with request details
Health Check Processing
- Probe Detection: Identifies probe requests via
probe=trueparameter - Direct Response: Returns request object directly without processing
- Monitoring: Supports service health monitoring and availability checks
Performance Characteristics
Processing Metrics
- Throughput: ~1000 requests per second
- Latency: <50ms average response time
- Memory Usage: ~32MB average
- CPU Usage: Minimal (I/O bound operations)
Scalability Features
- Stateless Design: No state management, fully scalable
- Lightweight Processing: Minimal computational overhead
- Fast Response: Quick request validation and response generation
- Concurrent Handling: Supports high concurrent request volumes
Dependencies
External Services
- Application Insights: Telemetry and logging
- Azure Functions Runtime: Hosting platform
Key NPM Packages
idgen: Unique identifier generationquery-string: URL query parameter parsing
Configuration
Environment-Specific Settings
- Development: Basic logging configuration
- Integration: Integration testing settings
- Production: Production logging and monitoring
Key Configuration Elements
- Application Insights connection string
- Logging levels
- Environment identification
Error Handling
Error Scenarios
- Missing Required Parameters: Request lacks required
typeparameter - Malformed Requests: Invalid request format or structure
- Processing Exceptions: Unexpected errors during request handling
Error Response Strategy
- Detailed Error Messages: Comprehensive error descriptions
- Error Logging: Full error context logging for debugging
- Graceful Degradation: Service continues operating despite individual request failures
- Standardized Error Format: Consistent error response structure
Monitoring and Observability
Logging
- Structured logging with configurable levels
- Request/response logging for debugging
- Error logging with full context
- Performance metrics logging
Metrics
- Request processing rates
- Response time percentiles
- Error rates and types
- Health check success rates
Application Insights Integration
- Custom telemetry for request tracking
- Performance counters
- Exception tracking
- Dependency monitoring
Security Considerations
- Anonymous Access: No authentication required (internal utility service)
- Input Validation: Basic parameter validation to prevent malformed requests
- Logging Security: Secure handling of request data in logs
- No Sensitive Data: Service doesn't handle sensitive business data
Use Cases
Primary Use Cases
- Integration Testing: Testing HTTP request/response flows
- Debugging: Logging and analyzing request patterns
- Health Monitoring: Service availability and health checks
- Development Workflows: Request validation during development
- Load Testing: Simple endpoint for performance testing
Integration Scenarios
- API Gateway Testing: Validating API gateway configurations
- Load Balancer Health Checks: Endpoint for load balancer monitoring
- Development Debugging: Request flow analysis and troubleshooting
- Integration Testing: Validating request formats and parameters
Related Services
This service integrates with the broader Publisher ecosystem as: - Utility Service: Provides testing and debugging capabilities - Health Check Endpoint: Supports monitoring and alerting systems - Development Tool: Assists in development and testing workflows - Integration Helper: Supports integration testing scenarios
Troubleshooting
Common Issues
- Missing Type Parameter: Ensure requests include required
typequery parameter - Health Check Failures: Verify probe parameter format and service availability
- Response Format Issues: Check response parsing and handling logic
- Logging Problems: Verify Application Insights configuration
Debug Steps
- Check Application Insights for request traces
- Verify query parameter format and encoding
- Review service logs for error patterns
- Test with simple probe requests
Development
Local Development Setup
- Clone repository
- Install dependencies:
npm install - Configure Application Insights connection
- Run tests:
npm test - Start locally:
func start
Testing
# Health check test
curl "http://localhost:7071/api/postresponder?probe=true"
# Normal request test
curl "http://localhost:7071/api/postresponder?type=test"
# Error test (missing type parameter)
curl "http://localhost:7071/api/postresponder"
Code Structure
index.js: Azure Function entry point with query parsingsrc/Handler.js: Main request processing logicconfig/: Environment-specific configurations
Future Enhancements
Potential Improvements
- Request Validation: Enhanced parameter validation and sanitization
- Response Formats: Support for multiple response formats (XML, plain text)
- Request Transformation: Basic request transformation capabilities
- Enhanced Monitoring: Additional metrics and monitoring capabilities