0
0
Rest APIprogramming~10 mins

Statelessness requirement 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 add a stateless header to the HTTP response.

Rest API
response.headers['[1]'] = 'no-store'
Drag options to blanks, or click blank then click option'
AAuthorization
BUser-Agent
CContent-Type
DCache-Control
Attempts:
3 left
💡 Hint
Common Mistakes
Using Authorization header instead of Cache-Control
Forgetting to set any header for statelessness
2fill in blank
medium

Complete the code to extract the client state from the request in a stateless API.

Rest API
client_state = request.headers.get('[1]')
Drag options to blanks, or click blank then click option'
ACookie
BHost
CAuthorization
DContent-Length
Attempts:
3 left
💡 Hint
Common Mistakes
Using Cookie header which implies server-side session
Using Content-Length which is unrelated to client state
3fill in blank
hard

Fix the error in the code to ensure the API remains stateless by avoiding server-side session storage.

Rest API
session['user'] = [1]
Drag options to blanks, or click blank then click option'
Arequest.headers.get('Authorization')
Brequest.cookies.get('session_id')
Cdatabase.query_user()
Dcache.get('user')
Attempts:
3 left
💡 Hint
Common Mistakes
Storing user info in session or cache breaks statelessness
Using cookies implies server-side session
4fill in blank
hard

Fill both blanks to create a stateless API endpoint that reads client token and returns a response without server session.

Rest API
def get_data(request):
    token = request.headers.get('[1]')
    data = fetch_data(token)
    return [2](data)
Drag options to blanks, or click blank then click option'
AAuthorization
Bjsonify
Crender_template
DCookie
Attempts:
3 left
💡 Hint
Common Mistakes
Using Cookie header which implies server session
Using render_template which may rely on server state
5fill in blank
hard

Fill all three blanks to implement a stateless POST endpoint that validates a token, processes data, and returns JSON response.

Rest API
def post_data(request):
    token = request.headers.get('[1]')
    if not validate_[2](token):
        return [3]({'error': 'Unauthorized'}, 401)
    result = process(request.json)
    return jsonify(result)
Drag options to blanks, or click blank then click option'
AAuthorization
Btoken
Cmake_response
DCookie
Attempts:
3 left
💡 Hint
Common Mistakes
Using Cookie header breaks statelessness
Returning raw dict without response wrapper may cause issues