0
0
Rest APIprogramming~10 mins

Webhook registration endpoint in Rest API - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to define the HTTP method for the webhook registration endpoint.

Rest API
app.route('/webhook/register', methods=[[1]])
def register_webhook():
    return 'Webhook registered', 200
Drag options to blanks, or click blank then click option'
A"GET"
B"DELETE"
C"POST"
D"PUT"
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET method which is for retrieving data, not for registration.
Using DELETE or PUT which are for other purposes.
2fill in blank
medium

Complete the code to extract the webhook URL from the JSON request body.

Rest API
data = request.get_json()
webhook_url = data[1]
Drag options to blanks, or click blank then click option'
A["webhook_url"]
B["url"]
C["callback"]
D["endpoint"]
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect keys like "webhook_url" or "callback" which may not exist.
Forgetting to parse JSON before accessing keys.
3fill in blank
hard

Fix the error in the code to validate the webhook URL format.

Rest API
if not webhook_url.startswith([1]):
    return 'Invalid URL', 400
Drag options to blanks, or click blank then click option'
A"http://"
B"www."
C"ftp://"
D"https://"
Attempts:
3 left
💡 Hint
Common Mistakes
Allowing non-secure URLs starting with "http://".
Using incorrect prefixes like "ftp://" or "www.".
4fill in blank
hard

Fill both blanks to store the webhook URL and respond with success.

Rest API
registered_webhooks.append([1])
return [2], 201
Drag options to blanks, or click blank then click option'
Awebhook_url
B'Webhook registered successfully'
C'Registration failed'
Dwebhook_url.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Returning failure message instead of success.
Appending the wrong variable or modifying the URL unnecessarily.
5fill in blank
hard

Fill all three blanks to complete the webhook registration function with error handling.

Rest API
def register_webhook():
    data = request.get_json()
    webhook_url = data[1]
    if not webhook_url.startswith([2]):
        return 'Invalid URL', 400
    registered_webhooks.append([3])
    return 'Webhook registered', 201
Drag options to blanks, or click blank then click option'
A["url"]
B"https://"
Cwebhook_url
D["callback"]
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong keys to extract the URL.
Not validating the URL prefix properly.
Appending incorrect variables.