0
0
Rest APIprogramming~10 mins

Webhook testing strategies 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 send a test webhook POST request using curl.

Rest API
curl [1] 'https://example.com/webhook' -d '{"event":"test"}'
Drag options to blanks, or click blank then click option'
A-d
B-H 'Content-Type: application/json'
C-X POST
D-X GET
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST
Omitting the HTTP method option
2fill in blank
medium

Complete the code to verify the webhook payload signature in Python.

Rest API
import hmac
import hashlib

def verify_signature(payload, signature, secret):
    expected = hmac.new(secret.encode(), payload, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, [1])
Drag options to blanks, or click blank then click option'
Ahashlib.sha256
Bpayload
Csecret
Dsignature
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing with payload instead of signature
Not encoding the secret
3fill in blank
hard

Fix the error in the Node.js webhook test server code to parse JSON body correctly.

Rest API
const express = require('express');
const app = express();

app.use([1]);

app.post('/webhook', (req, res) => {
  console.log(req.body);
  res.sendStatus(200);
});
Drag options to blanks, or click blank then click option'
Aexpress.json()
Bexpress.urlencoded()
Cexpress.text()
DbodyParser.json()
Attempts:
3 left
💡 Hint
Common Mistakes
Using express.urlencoded() for JSON
Not using any body parser middleware
4fill in blank
hard

Fill both blanks to create a Python dictionary comprehension that filters webhook events with type 'payment'.

Rest API
filtered_events = {event['id']: event for event in events if event[1] [2] 'payment'}
Drag options to blanks, or click blank then click option'
A['type']
B==
C!=
D['id']
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' instead of '=='
Accessing wrong dictionary key
5fill in blank
hard

Fill all three blanks to build a JavaScript object from webhook data filtering only events with status 'success'.

Rest API
const successEvents = Object.fromEntries(
  Object.entries(data).filter(([[1], [2]]) => [3] === 'success')
);
Drag options to blanks, or click blank then click option'
Akey
Bvalue
Cvalue.status
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'status' instead of 'value.status'
Swapping key and value names