Bird
Raised Fist0
Rest APIprogramming~20 mins

Webhook registration endpoint in Rest API - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Webhook Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
1:30remaining
What is the output of this webhook registration response?
Consider a webhook registration endpoint that returns a JSON response confirming the registration. What will be the output of the following code snippet when the webhook is successfully registered?
Rest API
response = {
  "status": "success",
  "message": "Webhook registered successfully",
  "webhook_id": 12345
}
print(response)
A{"status": "success", "message": "Webhook registered successfully", "webhook_id": 12345}
B{'status': 'success', 'message': 'Webhook registered successfully', 'webhook_id': 12345}
CWebhook registered successfully with ID 12345
DError: webhook_id missing
Attempts:
2 left
💡 Hint
Look at how Python prints dictionaries.
🧠 Conceptual
intermediate
1:00remaining
Which HTTP method is typically used to register a webhook?
When creating a webhook registration endpoint, which HTTP method should be used to send the registration request?
APOST
BGET
CDELETE
DPUT
Attempts:
2 left
💡 Hint
Think about sending data to create a new resource.
🔧 Debug
advanced
2:00remaining
What error does this webhook registration code raise?
This Python Flask code snippet is intended to register a webhook but raises an error. What error does it raise?
Rest API
from flask import Flask, request, jsonify
app = Flask(__name__)

@app.route('/register_webhook', methods=['POST'])
def register_webhook():
    data = request.json
    url = data['url']
    if not url.startswith('http'):
        return jsonify({'error': 'Invalid URL'}), 400
    # Save webhook logic here
    return jsonify({'status': 'success', 'webhook_url': url})

# Missing app.run() call
ATypeError: 'str' object is not callable
BRuntimeError: Working outside of request context
CAttributeError: 'NoneType' object has no attribute 'startswith'
DNo error, runs successfully
Attempts:
2 left
💡 Hint
Check what happens if request.json is None.
📝 Syntax
advanced
1:30remaining
Which option contains the correct JSON schema snippet for webhook registration?
You want to define a JSON schema for validating webhook registration data. Which option is syntactically correct?
A
{
  "type": "object",
  "properties": {
    "url": {"type": "string", "format": "uri"},
    "events": {"type": "array", "items": {"type": "string"}}
  },
  "required": [url, events]
}
B
{
  type: "object",
  properties: {
    url: {type: "string", format: "uri"},
    events: {type: "array", items: {type: "string"}}
  },
  required: ["url", "events"]
}
C
{
  "type": "object",
  "properties": {
    "url": {"type": "string", "format": "uri"},
    "events": {"type": "array", "items": {"type": "string"}}
  },
  required: ["url", "events"]
}
D
{
  "type": "object",
  "properties": {
    "url": {"type": "string", "format": "uri"},
    "events": {"type": "array", "items": {"type": "string"}}
  },
  "required": ["url", "events"]
}
Attempts:
2 left
💡 Hint
JSON keys and string values must be in double quotes.
🚀 Application
expert
2:00remaining
What is the number of unique events registered after these webhook registrations?
Assume a webhook registration system where each registration includes a list of events. Given these three registrations, how many unique events are registered in total? Registration 1: events = ["create", "update"] Registration 2: events = ["delete", "update"] Registration 3: events = ["create", "archive"]
A4
B5
C3
D6
Attempts:
2 left
💡 Hint
Count each event only once across all registrations.

Practice

(1/5)
1.

What is the main purpose of a webhook registration endpoint in a REST API?

easy
A. To update the API documentation automatically
B. To send event data directly to all users
C. To store user login credentials securely
D. To let apps register their callback URL to receive event updates

Solution

  1. Step 1: Understand webhook registration

    A webhook registration endpoint allows external apps to tell your system where to send event notifications.
  2. Step 2: Identify the main function

    The main function is to register a callback URL and event type so your system knows where to send updates.
  3. Final Answer:

    To let apps register their callback URL to receive event updates -> Option D
  4. Quick Check:

    Webhook registration = register callback URL [OK]
Hint: Webhook registration means saving callback URLs for events [OK]
Common Mistakes:
  • Confusing webhook registration with sending events
  • Thinking it stores user credentials
  • Assuming it updates documentation
2.

Which HTTP method is typically used to register a webhook endpoint?

easy
A. POST
B. GET
C. DELETE
D. PUT

Solution

  1. Step 1: Recall HTTP methods for creating resources

    POST is used to send data to the server to create a new resource, like registering a webhook.
  2. Step 2: Eliminate other methods

    GET retrieves data, DELETE removes data, PUT updates existing data. Registration is creation, so POST fits best.
  3. Final Answer:

    POST -> Option A
  4. Quick Check:

    Register webhook = POST request [OK]
Hint: Use POST to send data and create webhook registrations [OK]
Common Mistakes:
  • Using GET instead of POST for registration
  • Confusing PUT with POST
  • Using DELETE by mistake
3.

Given this JSON payload sent to a webhook registration endpoint:
{"callback_url": "https://example.com/hook", "event": "order_created"}
What should the server respond if the registration is successful?

medium
A. {"status": "success", "message": "Webhook registered"}
B. {"error": "Invalid URL"}
C. {"status": "failed", "message": "Missing event type"}
D. {"status": "success", "message": "Webhook deleted"}

Solution

  1. Step 1: Analyze the input payload

    The payload contains a valid callback URL and an event type, so it should be accepted.
  2. Step 2: Determine expected success response

    On success, the server confirms registration with a success status and message.
  3. Final Answer:

    {"status": "success", "message": "Webhook registered"} -> Option A
  4. Quick Check:

    Valid input = success confirmation [OK]
Hint: Success means status success and confirmation message [OK]
Common Mistakes:
  • Confusing error messages as success
  • Ignoring missing fields
  • Mixing registration and deletion messages
4.

Consider this snippet of a webhook registration handler in Python Flask:

from flask import Flask, request, jsonify
app = Flask(__name__)

@app.route('/register', methods=['POST'])
def register_webhook():
    data = request.json
    if 'callback_url' not in data or 'event' not in data:
        return jsonify({'error': 'Missing fields'}), 400
    # Assume registration logic here
    return jsonify({'status': 'success', 'message': 'Webhook registered'})

What error will occur if the client sends an empty POST body?

medium
A. No error, returns success
B. TypeError because request.json is a string
C. TypeError because data is None and keys are accessed
D. 404 Not Found error

Solution

  1. Step 1: Understand request.json behavior on empty body

    If the POST body is empty, request.json returns None, not a dictionary.
  2. Step 2: Analyze the if condition

    The code tries to check keys in data, but data is None, so 'in' operation causes a TypeError.
  3. Final Answer:

    TypeError because data is None and keys are accessed -> Option C
  4. Quick Check:

    Empty body means request.json is None causing key access error [OK]
Hint: Empty JSON body makes request.json None, causing TypeError [OK]
Common Mistakes:
  • Assuming empty body returns empty dict
  • Expecting success without data
  • Confusing error types
5.

You want to build a webhook registration endpoint that only accepts URLs starting with https:// and event types from a fixed list: ["order_created", "order_shipped"]. Consider this Python validation function:

def validate_webhook(data):
    callback = data.get('callback_url')
    event = data.get('event')
    if not callback.startswith('https://'):
        return False
    if event not in ['order_created', 'order_shipped']:
        return False
    return True

Which statement best describes its behavior?

hard
A. Correctly validates both URL scheme and event type
B. Fails if callback_url is missing, causing AttributeError
C. Allows any URL scheme, no validation done
D. Only checks event type, ignores URL

Solution

  1. Step 1: Check callback_url usage

    The code calls startswith on callback without checking if callback is None, so if missing, it raises AttributeError.
  2. Step 2: Verify event type check

    The event type check is correct, but the missing callback check causes failure before this.
  3. Final Answer:

    Fails if callback_url is missing, causing AttributeError -> Option B
  4. Quick Check:

    Missing callback_url causes error on startswith call [OK]
Hint: Check for None before calling string methods to avoid errors [OK]
Common Mistakes:
  • Not checking if callback_url exists before startswith
  • Assuming event type validation covers all errors
  • Ignoring input validation order
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard