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.
Understanding controllers - Nest.js Tutorial
From the course: Mastering Nest.js: Build Scalable Applications with Mastery in Nest.js Framework
Understanding controllers
Controllers are considered as one of the most important and crucial fragments in NestJS. As controllers are responsible for handling incoming HTTP requests and returning responses back to the client. Controllers not only manage incoming HTTP requests, but also contain the logic for handling specific routes. There can be multiple controllers handling multiple HTTP requests at the same time. The routing mechanism of the controller controls which request should be passed to a specific controller. Each controller has more than one route and different routes perform different actions. Let's understand the controller syntax and implement a simple example. So here we have the controller decorator which handles the HTTP request. We can mark any class as controller by specifying the add controller, that is, the controller decorator. Inside the class, there is a get decorator to handle the HTTP GET requests. The controller decorator takes a string argument, which basically acts as a route path…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
(Locked)
Understanding controllers5m 10s
-
(Locked)
Controller fundamentals (@Get handler)4m 21s
-
(Locked)
Controller fundamentals (Headers)3m 35s
-
(Locked)
Controller fundamentals (@Post handler)8m 57s
-
(Locked)
Controller fundamentals (@Post handler), part 2 with modules6m 56s
-
(Locked)
Controller fundamentals (fetching params)6m 44s
-
(Locked)
Controller fundamentals (@Put handler)10m 18s
-
(Locked)
Controller fundamentals (@Patch handler)4m 8s
-
(Locked)
Controller fundamentals (@Delete handler)3m 24s
-
(Locked)
Request object4m 42s
-
(Locked)
Response object2m 6s
-
(Locked)
Fetching queries3m 24s
-
(Locked)
@HttpCode vs. @Res decorator3m 22s
-
(Locked)
HTTP response status2m 53s
-
(Locked)
-
-
-
-
-
-
-
-
-
-