0
0
Rest APIprogramming~10 mins

301 and 302 redirects 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 301 redirect response in a REST API.

Rest API
response.status_code = [1]
Drag options to blanks, or click blank then click option'
A301
B200
C404
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using 302 instead of 301 for permanent redirect
Using 200 which means OK, not redirect
2fill in blank
medium

Complete the code to send a 302 redirect response in a REST API.

Rest API
response.status_code = [1]
Drag options to blanks, or click blank then click option'
A400
B301
C503
D302
Attempts:
3 left
💡 Hint
Common Mistakes
Using 301 instead of 302 for temporary redirect
Using 400 which means bad request
3fill in blank
hard

Fix the error in setting the redirect status code to 301 in this REST API code.

Rest API
response.status_code = [1]
Drag options to blanks, or click blank then click option'
A301
B302
C200
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 301 and 302 status codes
Using 200 which means success, not redirect
4fill in blank
hard

Fill both blanks to set a 302 redirect with the correct Location header.

Rest API
response.status_code = [1]
response.headers['Location'] = [2]
Drag options to blanks, or click blank then click option'
A302
B'https://newsite.com'
C'https://example.com'
D301
Attempts:
3 left
💡 Hint
Common Mistakes
Using 301 status code with 302 redirect
Setting Location header to wrong URL
5fill in blank
hard

Fill all three blanks to set a 301 redirect with a Location header and a message body.

Rest API
response.status_code = [1]
response.headers['Location'] = [2]
response.body = [3]
Drag options to blanks, or click blank then click option'
A301
B'https://permanent.com'
C'Resource moved permanently'
D302
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing 301 and 302 codes
Forgetting to set Location header
Leaving body empty or incorrect