0
0
Rest APIprogramming~20 mins

Webhook testing strategies in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Webhook Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Webhook Retry Mechanisms

When testing a webhook, why is it important to simulate delayed or failed responses from the receiving server?

ATo confirm the webhook sender uses the correct HTTP method
BTo verify that the webhook sender retries sending the payload according to the retry policy
CTo check if the webhook payload is encrypted during transmission
DTo ensure the webhook URL is publicly accessible
Attempts:
2 left
💡 Hint

Think about what happens if the receiver is temporarily down or slow.

Predict Output
intermediate
2:00remaining
Webhook Payload Validation Output

Given the following webhook payload validation code snippet, what will be the output if the payload misses the required event_type field?

Rest API
def validate_payload(payload):
    if 'event_type' not in payload:
        return 'Invalid payload: missing event_type'
    return 'Payload valid'

result = validate_payload({'data': 'value'})
print(result)
AInvalid payload: missing event_type
BPayload valid
CKeyError: 'event_type'
DNone
Attempts:
2 left
💡 Hint

Check what happens when the key is not found in the dictionary.

🔧 Debug
advanced
3:00remaining
Debugging Webhook Signature Verification Failure

Consider this webhook signature verification snippet. It always returns False even with correct signatures. What is the cause?

Rest API
import hmac
import hashlib

def verify_signature(secret, payload, signature):
    computed = hmac.new(secret.encode(), payload.encode(), hashlib.sha256).hexdigest()
    return computed == signature

# Usage
secret = 'mysecret'
payload = '{"id":123}'
signature = '5d41402abc4b2a76b9719d911017c592'
print(verify_signature(secret, payload, signature))
APayload should be decoded before hashing
BThe secret key is not encoded properly
CThe signature is MD5 hash, but code uses SHA256 for verification
DThe comparison should use hmac.compare_digest()
Attempts:
2 left
💡 Hint

Check the hashing algorithm used for the signature and verification.

📝 Syntax
advanced
2:00remaining
Identify Syntax Error in Webhook Listener Code

Which option contains a syntax error that would prevent a webhook listener from running?

Rest API
from flask import Flask, request
app = Flask(__name__)

@app.route('/webhook', methods=['POST'])
def webhook_listener():
    data = request.json
    print('Received:', data)
    return '', 200
A
def webhook_listener():
    data = request.json
    print('Received:', data)
    return '', 200
B
ef webhook_listener():
    data = request.json
    print('Received:', data)
    return '', 200
C
002 ,'' nruter    
)atad ,':devieceR'(tnirp    
nosj.tseuqer = atad    
:)(renetsil_koohbew fed
D
def webhook_listener()
    data = request.json
    print('Received:', data)
    return '', 200
Attempts:
2 left
💡 Hint

Look carefully at the function definition line.

🚀 Application
expert
3:00remaining
Determining Number of Valid Webhook Events Processed

A webhook receiver processes a list of events. It only accepts events with type equal to order.created or order.updated. Given the following event list, how many events will be processed?

Rest API
events = [
    {'id': 1, 'type': 'order.created'},
    {'id': 2, 'type': 'order.deleted'},
    {'id': 3, 'type': 'order.updated'},
    {'id': 4, 'type': 'customer.created'},
    {'id': 5, 'type': 'order.created'}
]

processed = [e for e in events if e['type'] in ('order.created', 'order.updated')]
print(len(processed))
A3
B2
C4
D5
Attempts:
2 left
💡 Hint

Count only events with type 'order.created' or 'order.updated'.