Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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
✗ Incorrect
The header value must be a string, so it needs to be in quotes like "Hello".
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect cache directives
Omitting quotes around the value
Using unrelated strings
✗ Incorrect
The correct value to prevent caching is "no-cache" as a string.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a number instead of a string
Using methods that return strings but not as literals
Omitting quotes
✗ Incorrect
Header values must be strings. Using "100" ensures the value is a string literal.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping header names and values
Omitting quotes
Using wrong header names
✗ Incorrect
The first blank is the header name "X-App-Version" and the second blank is its value "1.0".
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up header names and values
Using wrong values
Forgetting quotes
✗ Incorrect
The first header name is "X-User", its value is "admin", and the second header value is "editor" for "X-Role".