Training Day

Request-Response Pattern

Synchronous communication where a client makes a request and waits for a response

The request-response pattern is one of the most fundamental integration approaches, where a client sends a request to a server and waits for the server to respond.

Request-Response Overview

The request-response pattern has several key characteristics:

  • Synchronous: The client typically waits for a response before proceeding
  • Direct communication: Clear sender and receiver relationship
  • Immediate feedback: Client receives immediate confirmation of success or failure
  • Simple mental model: Follows natural question-answer paradigm
  • Stateless: Each request-response pair is typically self-contained

When to Use Request-Response

Request-response is ideal for scenarios where:

  • Immediate answers are required
  • Operations must complete before proceeding
  • Simple, direct interactions are needed
  • Low latency is expected
  • The client needs confirmation of success/failure
  • Data lookups or validations are performed

Request-Response Variations

Synchronous Request-Response

The client waits (blocks) until the server responds:

  • Direct coupling: Client operation pauses until response arrives
  • Simple implementation: Straightforward to code and understand
  • Immediate results: No additional mechanisms needed to retrieve response
  • Timeout handling: May require timeout management for slow responses
# Synchronous API call
Set Variable [$url; Value: "https://api.example.com/customers/123"]
Set Variable [$options; Value: "-X GET -H \"Content-Type: application/json\""]

# Client blocks until response is received or times out
Insert From URL [Select; $result; $url; cURL options: $options]

# Process response immediately
If [JSONGetElement($result; "status") = "success"]
  # Handle successful response
  ...
Else
  # Handle error
  ...
End If

Asynchronous Request-Response

The client doesn't block, but checks for the response later:

  • Non-blocking: Client continues processing while waiting
  • Callback mechanism: Client is notified when response arrives
  • Correlation ID: Used to match responses to requests
  • Greater complexity: Requires additional mechanisms to handle responses
# Initiate asynchronous request
Set Variable [$requestID; Value: Get(UUID)]
Set Variable [$url; Value: "https://api.example.com/long-process"]
Set Variable [$payload; Value: JSONSetElement("{}";
  ["process"; "generate_report"; JSONString];
  ["parameters"; $parameters; JSONObject];
  ["callback_id"; $requestID; JSONString]
)]
Set Variable [$options; Value: "-X POST -H \"Content-Type: application/json\" --data " & Quote($payload)]

# Make request but don't wait for full processing
Insert From URL [Select; $initialResponse; $url; cURL options: $options]

# Store request ID for later checking
Set Field [RequestLog::request_id; $requestID]
Set Field [RequestLog::status; "pending"]
Set Field [RequestLog::timestamp; Get(CurrentTimestamp)]

Fire and Forget

A request with no expected response:

  • Simplest form: Client sends request and continues
  • No confirmation: Client doesn't know if request succeeded
  • Lowest overhead: Minimal resource usage
  • Use case: Non-critical notifications or logging
# Fire and forget notification
Set Variable [$url; Value: "https://api.example.com/log-event"]
Set Variable [$payload; Value: JSONSetElement("{}";
  ["event"; "user_login"; JSONString];
  ["user_id"; $userID; JSONString];
  ["timestamp"; Get(CurrentTimestamp); JSONString]
)]
Set Variable [$options; Value: "-X POST -H \"Content-Type: application/json\" --data " & Quote($payload)]

# Send without waiting for or checking response
Insert From URL [Select; $result; $url; cURL options: $options]

# Continue processing immediately

FileMaker as Request Sender

FileMaker offers several ways to implement request-response:

Insert From URL

The primary script step for making HTTP requests:

# Basic REST API request
Set Variable [$url; Value: "https://api.example.com/products?category=electronics"]
Set Variable [$options; Value: "-X GET -H \"Accept: application/json\""]

Insert From URL [Select; $result; $url; cURL options: $options]

# Parse JSON response
Set Variable [$products; Value: JSONGetElement($result; "products")]

cURL Options

Configure detailed request parameters:

# More complex request with authentication and data
Set Variable [$url; Value: "https://api.example.com/orders"]
Set Variable [$data; Value: JSONSetElement("{}";
  ["customer_id"; $customerID; JSONString];
  ["items"; $items; JSONArray];
  ["shipping_address"; $address; JSONObject]
)]
Set Variable [$options; Value: "-X POST -H \"Content-Type: application/json\" -H \"Authorization: Bearer " & $token & "\" --data " & Quote($data)]

Insert From URL [Select; $result; $url; cURL options: $options]

Handling Responses

Processing different response types:

# Response handling with error checking
Set Variable [$statusCode; Value: GetAsNumber(JSONGetElement($result; "status"))]

If [$statusCode >= 200 and $statusCode < 300]
  # Success - process data
  Set Variable [$data; Value: JSONGetElement($result; "data")]
  ...
Else If [$statusCode >= 400 and $statusCode < 500]
  # Client error - handle invalid request
  Set Variable [$errorMessage; Value: JSONGetElement($result; "message")]
  Show Custom Dialog ["Request Error"; $errorMessage]
Else If [$statusCode >= 500]
  # Server error - retry or notify
  Set Variable [$retryCount; Value: $retryCount + 1]
  If [$retryCount <= 3]
    # Retry request
    Perform Script [Self; Parameter: $retryCount]
  Else
    # Give up and notify
    Show Custom Dialog ["Server Error"; "The service is currently unavailable. Please try again later."]
  End If
End If

FileMaker as Response Provider

FileMaker can also serve as the responder in request-response patterns:

Data API

FileMaker Server's REST API for external systems:

  • REST interface: Standard HTTP methods for CRUD operations
  • JSON format: Structured data exchange
  • Authentication: OAuth or basic authentication
  • Versioned API: Consistent interface across versions

Custom Web Publishing

Create custom endpoints for specialized needs:

  • PHP API: Traditional web publishing option
  • XML response: Structure data for clients
  • Custom business logic: Implement specific rules
  • Direct database access: Full control over data operations

Claris Connect Implementation

Claris Connect supports request-response patterns through:

  • HTTP actions: Make requests to external services
  • Response parsing: Extract data from responses
  • Conditional logic: React differently based on response content
  • Error handling: Manage failed requests
  • Transformation: Convert between different data formats

Example approach:

  1. Create a flow triggered by a schedule or event
  2. Add an HTTP action to make the request
  3. Parse the response using transformation steps
  4. Implement conditional logic based on the response
  5. Configure error handling for request failures

Common Request-Response Scenarios

Data Lookups

  • Customer information: Retrieve customer details by ID
  • Product data: Get current pricing and availability
  • Validation: Verify addresses, tax IDs, or other information

Transaction Processing

  • Payment processing: Submit payment info, get authorization
  • Order submission: Send order details, receive confirmation
  • Reservation systems: Check availability, make bookings

Authentication

  • Login flows: Submit credentials, receive tokens
  • Token validation: Verify authentication status
  • Permission checks: Determine if actions are allowed

Advantages and Challenges

Advantages

  • Simple to understand and implement
  • Immediate confirmation of success/failure
  • Clear communication path
  • Predictable behavior
  • Works well for simple integrations

Challenges

  • Blocking operations can cause performance issues
  • Timeout handling can be complex
  • Network reliability impacts effectiveness
  • Limited scalability with many concurrent requests
  • Not suitable for long-running operations

Best Practices

  1. Implement timeouts: Don't wait indefinitely for responses
  2. Handle all response codes: Plan for success, failure, and edge cases
  3. Consider retries: Implement backoff algorithms for transient failures
  4. Keep requests idempotent: Enable safe retry operations
  5. Validate responses: Don't assume response data is always valid
  6. Log transactions: Maintain an audit trail of requests and responses
  7. Use correlation IDs: Include unique identifiers to track requests
  8. Implement response caching: Cache responses for frequently used data