Request handlers
A basic GET request handler for the /entries
route registered in the EntryController could look like this:
import
{
Controller
,
Get
}
from
'@nestjs/common'
;
@
Controller
(
'entries'
)
export
class
EntryController
{
@
Get
()
index
()
:
Entry
[]
{
const
entries
:Entry
[]
=
this
.
entriesService
.
findAll
();
return
entries
;
}
The @Controller('entries')
decorator tells Nest.js to add an entries
prefix to all routes registered in the class. This prefix is optional. An equivalent way to setup this route would be as follows:
import
{
Controller
,
Get
}
from
'@nestjs/common'
;
@
Controller
()
export
class
EntryController
{
@
Get
(
'entries'
)
index
()
:
Entry
[]
{
const
entries
:Entry
[]
=
this
.
entriesService
.
findAll
();
return
entries
;
}
Here, we don’t specify a prefix in the @Controller()
decorator, but instead use the full route path in the @Get('entries')
decorator.
In both...