Recall & Review
beginner
What is the purpose of HTTP status codes in NestJS?
HTTP status codes tell the client if a request was successful or if there was an error. In NestJS, they help communicate the result of an API call clearly.
Click to reveal answer
beginner
How do you set a custom HTTP status code in a NestJS controller?
Use the @HttpCode() decorator above the controller method to set a custom status code, for example, @HttpCode(201) sets the status to 201 Created.
Click to reveal answer
beginner
What is the role of HTTP headers in NestJS responses?
HTTP headers carry extra information about the response, like content type or caching rules. In NestJS, you can set headers to control how clients handle the response.
Click to reveal answer
intermediate
How can you set HTTP headers in a NestJS controller method?
You can inject the Response object from Express using @Res() and then use res.set() or res.header() to add headers before sending the response.
Click to reveal answer
intermediate
What is the difference between using @Res() and returning a value directly in NestJS controllers regarding status codes and headers?
Using @Res() gives full control over the response, including headers and status codes, but you must manually send the response. Returning a value lets NestJS handle status codes and headers automatically based on decorators.
Click to reveal answer
Which decorator sets the HTTP status code for a NestJS controller method?
✗ Incorrect
The @HttpCode() decorator is used to set the HTTP status code for a controller method in NestJS.
How do you add a custom header to a response in NestJS?
✗ Incorrect
You add custom headers by injecting the Response object with @Res() and calling res.set() or res.header() before sending the response.
What status code does NestJS return by default for a successful GET request?
✗ Incorrect
By default, NestJS returns 200 OK for successful GET requests.
If you use @Res() in a controller method, what must you remember to do?
✗ Incorrect
When using @Res(), you must manually send the response with res.send() or res.json(), otherwise the client will not get a response.
Which header is commonly used to specify the type of content returned by a NestJS API?
✗ Incorrect
The Content-Type header tells the client what type of data is in the response, such as application/json.
Explain how to set both a custom status code and headers in a NestJS controller method.
Think about decorators and direct response manipulation.
You got /4 concepts.
Describe the difference between returning a value directly and using @Res() in NestJS controllers regarding response control.
Consider who controls the response sending.
You got /4 concepts.