Webhook Integration
Configure asynchronous webhooks in moclojer to trigger background requests to external APIs. Simulate real-world integrations with conditional triggers, delays, and template support.
Webhooks allow moclojer to send asynchronous background requests to external APIs when an endpoint receives a request. This enables realistic simulation of real-world integrations like notifications, logging, and third-party callbacks.
π― How Webhooks Work
When an endpoint with a webhook configuration receives a request:
moclojer responds immediately to the client with the configured response
In parallel, moclojer sends an asynchronous HTTP request to the webhook URL
The webhook executes independently without blocking the original response
sequenceDiagram
participant Client
participant moclojer
participant Webhook API
Client->>moclojer: POST /with-webhook
moclojer->>Client: 200 OK (immediate response)
Note over moclojer: Response sent!
par Async Webhook
moclojer-->>Webhook API: POST (background request)
Note over Webhook API: Processes webhook
Webhook API-->>moclojer: Response (ignored)
endπ Basic Configuration
What happens:
Client sends POST to
/ordersmoclojer responds with
201 Createdimmediatelymoclojer sends POST to
https://api.example.com/notificationsin the background
π§ Webhook Configuration Options
Required Fields
url
Target webhook endpoint URL
https://api.slack.com/webhooks/...
method
HTTP method
POST, PUT, PATCH
Optional Fields
sleep-time
60
Delay in seconds before sending webhook
if
true
Conditional expression to trigger webhook
body
(empty)
Request body (supports templates)
headers
{}
Custom headers
β±οΈ Delayed Webhooks
Simulate processing delays with sleep-time:
Use case: Simulate payment processing that takes time to complete.
ποΈ Conditional Webhooks
Use if conditions to trigger webhooks based on request data:
Supported Operators
=
Equals
json-params.status = "active"
>
Greater than
json-params.amount > 100
<
Less than
json-params.age < 18
>=
Greater or equal
json-params.score >= 50
<=
Less or equal
query-params.limit <= 100
Accessing Request Data in Conditions
π Real-World Examples
Example 1: Slack Notification
Example 2: Analytics Tracking
Example 3: Multi-Service Integration
π§ͺ Testing Webhooks
Using Request Bin
Create a request bin at webhook.site
Copy the unique URL
Configure your webhook:
Make a request to your endpoint
View the webhook payload at webhook.site
Local Testing with ngrok
β
Best Practices
Do:
β Use
sleep-timeto simulate realistic processing delaysβ Add conditions with
ifto trigger webhooks selectivelyβ Include correlation IDs for tracing (use
{{json-params.correlation_id}})β Test webhooks with request bins before production integration
β Use template variables to pass dynamic data
Don't:
β Rely on webhook responses (they're ignored by design)
β Use webhooks for critical synchronous operations
β Set
sleep-timetoo high in tests (slows down test suites)β Expose sensitive credentials in webhook URLs
π Security Considerations
π Use Cases
Order confirmation email
sleep-time: 0, immediate notification
Payment processing
sleep-time: 60-300, simulate processing time
Conditional alerts
if: json-params.priority = "high"
Multi-step workflows
Chain webhooks with delays
Third-party integrations
Slack, Discord, analytics platforms
π¨ Important Notes
Asynchronous Execution: moclojer does not wait for webhook responses. The webhook executes in the background and its response is ignored.
No Retries: Failed webhooks are not automatically retried. For production use, implement retry logic in your actual backend.
Template Support: Webhooks support all template variables:
path-params.*,query-params.*,json-params.*,header-params.*, and{{now}}.
π See Also
Template Variables - All available template variables
Path Parameters - Using path params in webhooks
Header Parameters - Forwarding headers
Real-World Example - Complete e-commerce example
Last updated
Was this helpful?