From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Controller fundamentals (Headers)

Controller fundamentals (Headers)

Alright, so we are continuing with the previous lecture score, where we are returning a string in the get handler. And we can all agree to the fact that this is a string response and not the actual response object, which we used to do with the ExpressJS right, where we have a request and response object in the method and we use to send the responses back to the client. But here with nest.js, we just return the body of the response and nest.js automatically infers the headers by just looking at the data that has to be returned. Nest.js automatically determines and sets the appropriate headers for the response based on the data returned from the route handler method. This eliminates the need for explicit header configuration, allowing developers to focus on the response content without manually specifying headers. So in the current example, we are returning the text that is a string response. Let's open the browser and see what type of headers NestJS has set for this response. I'll open…

Contents