Recall & Review
beginner
What is a custom response header in Spring Boot?
A custom response header is an additional piece of information added to the HTTP response by the server. In Spring Boot, you can add these headers to provide extra data to the client beyond the standard headers.
Click to reveal answer
beginner
How do you add a custom response header using Spring Boot's ResponseEntity?
You can add custom headers by creating an HttpHeaders object, adding your headers to it, and then passing it to ResponseEntity. For example: <br>
HttpHeaders headers = new HttpHeaders();<br>headers.add("X-Custom-Header", "value");<br>return new ResponseEntity<>(body, headers, HttpStatus.OK);Click to reveal answer
intermediate
What is the purpose of the @ResponseHeader annotation in Spring Boot?
Spring Boot does not have a @ResponseHeader annotation. Instead, you add custom headers using HttpServletResponse, ResponseEntity, or WebFilter. This is important to know to avoid confusion.
Click to reveal answer
beginner
How can you add a custom header using HttpServletResponse in a Spring Boot controller?
You can inject HttpServletResponse into your controller method and call
response.addHeader("X-Custom-Header", "value") before returning the response body.Click to reveal answer
beginner
Why might you want to add custom response headers in a web application?
Custom headers can provide extra information like security tokens, version info, or debugging data. They help clients understand or handle the response better without changing the response body.
Click to reveal answer
Which class in Spring Boot is commonly used to add custom response headers?
✗ Incorrect
HttpHeaders is used to set custom headers in the response.
How do you add a custom header using HttpServletResponse?
✗ Incorrect
The addHeader method adds a new header to the response.
What is the correct way to return a response with custom headers using ResponseEntity?
✗ Incorrect
The constructor takes body, headers, then status in that order.
Which of these is NOT a reason to add custom response headers?
✗ Incorrect
Custom headers do not change the HTTP method.
Can you add multiple custom headers in Spring Boot response?
✗ Incorrect
You can add as many headers as needed using HttpHeaders.
Explain how to add a custom response header in a Spring Boot controller using ResponseEntity.
Think about how you build the response with headers included.
You got /3 concepts.
Describe why custom response headers are useful in web applications.
Consider what extra data headers can carry.
You got /4 concepts.