gitlabEdit

โœ”๏ธValidate then Send

Learn the production-ready best practice of validating requests before dispatching, with complete implementation examples in 4 languages.

Overview

The Validate-then-Send pattern is a critical best practice for production integrations:

  1. Validate the request structure and data (fast, free, safe)

  2. Fix any validation errors

  3. Send the real dispatch once validation passes

This two-step approach prevents errors, saves credits, and ensures data quality before external API calls.

Why Validate First?

Benefits

Benefit
Impact

Catch errors early

Before external API calls, before credits charged

Free validation

No credits consumed for validation

Fast feedback

< 100ms response vs 2-10s for real dispatch

No side effects

No records created in external systems

Safe testing

Perfect for development and testing

Better UX

Show validation errors to users before submission

What Validation Checks

Validation performs comprehensive checks without calling external providers:

  • โœ… Request structure and required fields

  • โœ… Data types and format

  • โœ… Template existence and accessibility

  • โœ… Provider configuration presence

  • โœ… Business logic (amounts, dates, references)

  • โœ… Template data schema compliance

  • โŒ Does NOT call external provider APIs

  • โŒ Does NOT create real records

  • โŒ Does NOT charge credits

Prerequisites

  • Docs-Dispatcher account with email and password

  • At least one provider configured

  • Template created in Templater

  • Basic understanding of REST APIs

Step 1: Authentication

Dispatcher API uses HTTP Basic Authentication. You'll need your Dispatcher account email and password for all API calls.

Setup Credentials

circle-info

No token management needed! Unlike JWT-based APIs, Basic Auth doesn't require separate authentication endpoints or token refresh. Your credentials are sent with each request.

Quick links:

Step 2: Validate Request

Call the /validate endpoint with your complete request:

Validation Endpoint

Example Validation Request

Validation Success Response

Validation Error Response

Validation with Warnings

Step 3: Handle Validation Errors

When validation fails, fix the errors and re-validate.

Error Handling Pattern

Step 4: Send Dispatch

Once validation passes, send the real dispatch by changing the endpoint from /validate to the actual service endpoint.

From Validation to Dispatch

Validation (Step 2):

Real Dispatch (Step 4):

Same request body - just change the endpoint!

Send Request

Success Response

Complete Implementation Examples

curl (Complete Validate-Then-Send Flow)

Node.js (Complete Validate-Then-Send Flow)

PHP (Complete Validate-Then-Send Flow)

Java (Complete Validate-Then-Send Flow)

Best Practices

1. Always Validate in Development

2. Optional Validation in Production

3. Cache Validation Results

4. User Feedback Integration

5. CI/CD Integration

When to Skip Validation

You can skip validation in these scenarios:

  1. Known good data - Request structure proven correct

  2. Performance critical - Every millisecond counts

  3. Trusted input - Data from validated internal systems

  4. Batch processing - Pre-validated data sets

circle-exclamation

Troubleshooting

Issue: "Validation passes but dispatch fails"

Cause: Validation doesn't check external provider state

Solution:

  • Validation checks request structure only

  • Provider may reject due to business rules (duplicate invoice, etc.)

  • Implement proper error handling for dispatch step

Issue: "Validation too slow"

Cause: Network latency or large request

Solution:

  • Cache validation results for identical requests

  • Validate critical fields only in some cases

  • Use async validation with loading indicators

Next Steps

Core Concepts

Summary

You've learned:

  • โœ… Why validation before dispatch is critical

  • โœ… How to validate requests without side effects

  • โœ… Handling validation errors and warnings

  • โœ… Complete validate-then-send implementations in 4 languages

  • โœ… Best practices for production use

  • โœ… When to skip validation

Validation is your safety net - use it to catch errors early, save credits, and deliver better user experiences!

Last updated