Bird
0
0

You want to test a Flask route that requires a custom header X-API-KEY. How do you include this header in a test client GET request?

hard📝 Application Q8 of 15
Flask - Testing Flask Applications
You want to test a Flask route that requires a custom header X-API-KEY. How do you include this header in a test client GET request?
Aclient.get('/data', data={'X-API-KEY': 'secret'})
Bclient.get('/data', headers={'X-API-KEY': 'secret'})
Cclient.get('/data', params={'X-API-KEY': 'secret'})
Dclient.get('/data', cookies={'X-API-KEY': 'secret'})
Step-by-Step Solution
Solution:
  1. Step 1: Recall how to send headers with test client

    Headers are passed using the headers argument as a dictionary.
  2. Step 2: Match correct argument usage

    client.get('/data', headers={'X-API-KEY': 'secret'}) correctly uses headers={'X-API-KEY': 'secret'} in the GET request.
  3. Final Answer:

    client.get('/data', headers={'X-API-KEY': 'secret'}) -> Option B
  4. Quick Check:

    Use headers= dict to send custom headers [OK]
Quick Trick: Use headers= dict to add custom headers in test client requests [OK]
Common Mistakes:
MISTAKES
  • Passing headers as data or params
  • Using cookies instead of headers
  • Forgetting to use dictionary for headers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes