0
0
Spring Bootframework~10 mins

Custom response headers in Spring Boot - 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 custom header named "X-Custom-Header" with value "Hello" to the response.

Spring Boot
return ResponseEntity.ok().header("X-Custom-Header", [1]).body("Success");
Drag options to blanks, or click blank then click option'
A"Hello"
BHello
C"X-Custom-Header"
D200
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the header value
Using the header name as the value
Using a number instead of a string
2fill in blank
medium

Complete the code to set the "Cache-Control" header to "no-cache" in the response.

Spring Boot
return ResponseEntity.ok().header("Cache-Control", [1]).body("Data");
Drag options to blanks, or click blank then click option'
A"no-cache"
B"cache"
C"private"
D"public"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect cache directives
Omitting quotes around the value
Using unrelated strings
3fill in blank
hard

Fix the error in the code to add a header "X-Rate-Limit" with value 100 as a string.

Spring Boot
return ResponseEntity.ok().header("X-Rate-Limit", [1]).body("Limit set");
Drag options to blanks, or click blank then click option'
A100
B"100"
CString.valueOf(100)
DInteger.toString(100)
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a number instead of a string
Using methods that return strings but not as literals
Omitting quotes
4fill in blank
hard

Fill both blanks to add header "X-App-Version" with value "1.0".

Spring Boot
return ResponseEntity.ok().header([1], [2]).body("Info");
Drag options to blanks, or click blank then click option'
A"X-App-Version"
B"1.0"
C"X-Env"
D"prod"
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping header names and values
Omitting quotes
Using wrong header names
5fill in blank
hard

Fill all three blanks to add headers "X-User" with value "admin", "X-Role" with value "editor", and "X-Status" with value "active".

Spring Boot
return ResponseEntity.ok()
  .header([1], [2])
  .header("X-Role", [3])
  .header("X-Status", "active")
  .body("User info");
Drag options to blanks, or click blank then click option'
A"X-User"
B"admin"
C"editor"
D"guest"
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up header names and values
Using wrong values
Forgetting quotes