0
0
Rest APIprogramming~20 mins

401 Unauthorized vs 403 Forbidden in Rest API - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
HTTP Status Code Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding 401 Unauthorized

Which statement best describes the HTTP 401 Unauthorized status code?

AThe server understood the request but refuses to authorize it.
BThe server encountered an unexpected condition.
CThe requested resource is not found on the server.
DThe client must authenticate itself to get the requested response.
Attempts:
2 left
💡 Hint

Think about when the server asks for credentials.

🧠 Conceptual
intermediate
1:30remaining
Understanding 403 Forbidden

Which statement best describes the HTTP 403 Forbidden status code?

AThe server cannot find the requested resource.
BThe client must authenticate itself to get the requested response.
CThe server refuses to authorize the request even if the client is authenticated.
DThe request was malformed or invalid.
Attempts:
2 left
💡 Hint

Think about when authentication is done but access is denied.

Predict Output
advanced
2:00remaining
Identify the HTTP status code returned

What HTTP status code will this API return if the client sends no authentication token?

Rest API
def api_request(auth_token=None):
    if auth_token is None:
        return 401
    elif auth_token == 'valid_token':
        return 200
    else:
        return 403

print(api_request())
A401
B200
C403
D500
Attempts:
2 left
💡 Hint

Check what happens when auth_token is None.

Predict Output
advanced
2:00remaining
Determine the HTTP status code for invalid token

What HTTP status code will this API return if the client sends an invalid authentication token?

Rest API
def api_request(auth_token=None):
    if auth_token is None:
        return 401
    elif auth_token == 'valid_token':
        return 200
    else:
        return 403

print(api_request('invalid_token'))
A403
B404
C401
D200
Attempts:
2 left
💡 Hint

Check what happens when auth_token is not None and not valid.

🚀 Application
expert
2:30remaining
Choose the correct HTTP status code for a scenario

A user tries to access a private page on a website. They are logged in but do not have permission to view this page. Which HTTP status code should the server return?

A404 Not Found
B403 Forbidden
C401 Unauthorized
D500 Internal Server Error
Attempts:
2 left
💡 Hint

The user is authenticated but not allowed to access the resource.