0
0
Rest APIprogramming~20 mins

Why webhooks push notifications in Rest API - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Webhook Notification Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why do webhooks push notifications instead of polling?

Imagine you want to get updates from a service as soon as something changes. Why would a webhook push notifications instead of you asking repeatedly (polling)?

ABecause polling is faster and more efficient than pushing notifications.
BBecause pushing notifications saves resources by sending updates only when needed, avoiding constant checking.
CBecause webhooks cannot send data automatically and require manual requests.
DBecause pushing notifications requires the client to ask for updates every few seconds.
Attempts:
2 left
💡 Hint

Think about how often you want to check your mailbox versus being told when mail arrives.

Predict Output
intermediate
2:00remaining
What is the output of this webhook simulation code?

Consider this Python code simulating a webhook notification system. What will it print?

Rest API
def webhook_notify(event):
    if event == 'update':
        return 'Notification sent'
    else:
        return 'No notification'

print(webhook_notify('update'))
ANo notification
BNotification failed
CError: undefined variable
DNotification sent
Attempts:
2 left
💡 Hint

Look at the event value passed to the function.

🔧 Debug
advanced
2:00remaining
Why does this webhook notification code fail to send updates?

Look at this JavaScript code snippet meant to send webhook notifications. Why does it fail?

Rest API
async function sendWebhook(data) {
  fetch('https://example.com/webhook', {
    method: 'POST',
    body: JSON.stringify(data),
  });
}

sendWebhook({ event: 'update' });
ABecause fetch is missing headers specifying content type, so server rejects the request.
BBecause fetch requires await or then to handle the promise, otherwise it fails silently.
CBecause the URL is incorrect and causes a DNS error.
DBecause the method should be GET, not POST.
Attempts:
2 left
💡 Hint

Check what the server expects in the request headers.

📝 Syntax
advanced
2:00remaining
Which option correctly defines a webhook handler function in Python?

Choose the correct Python function syntax to handle webhook POST requests.

A
def webhook_handler(request):
    if request.method == 'POST':
        return 'Received'
    else:
        return 'Invalid method'
B
def webhook_handler(request):
    if request.method = 'POST':
        return 'Received'
    else:
        return 'Invalid method'
C
def webhook_handler(request):
    if request.method == 'POST'
        return 'Received'
    else:
        return 'Invalid method'
D
def webhook_handler(request):
    if request.method == 'POST':
        return 'Received'
    else
        return 'Invalid method'
Attempts:
2 left
💡 Hint

Remember Python requires colons after if and else statements and uses '==' for comparison.

🚀 Application
expert
2:00remaining
How many webhook notifications are sent in this scenario?

A webhook is set to notify on 'create' and 'delete' events. The system processes these events in order: ['create', 'update', 'delete', 'create', 'delete']. How many notifications will be sent?

A5
B3
C4
D2
Attempts:
2 left
💡 Hint

Count only events that match 'create' or 'delete'.