Complete the code to create a basic NestJS controller method that handles GET requests.
import { Controller, [1] } from '@nestjs/common'; @Controller('hello') export class HelloController { @[1]() getHello() { return 'Hello World!'; } }
The @Get() decorator marks the method to handle HTTP GET requests in NestJS controllers.
Complete the code to create an Express route handler that responds with 'Hello Express!'.
import express from 'express'; const app = express(); app.[1]('/', (req, res) => { res.send('Hello Express!'); });
res.send() to send a response.The app.get() method defines a route handler for HTTP GET requests in Express.
Fix the error in the Fastify route registration to correctly handle GET requests.
import Fastify from 'fastify'; const fastify = Fastify(); fastify.[1]('/', async (request, reply) => { return 'Hello Fastify!'; });
Fastify uses fastify.get() to register handlers for GET requests.
Fill both blanks to create a NestJS controller method that uses Express's response object to send JSON.
import { Controller, Injectable, [1] } from '@nestjs/common'; import { Response } from 'express'; @Controller() @Injectable() export class AppController { @[1]() sendJson(res: [2]) { res.json({ message: 'Hello from NestJS with Express!' }); } }
In NestJS, the @Res() decorator injects the Express response object, which is of type Response.
Fill all three blanks to create a Fastify route with schema validation and a handler that returns a greeting.
fastify.route({
method: '[1]',
url: '/greet',
schema: {
querystring: {
type: 'object',
properties: {
name: { type: 'string' }
},
required: ['[2]']
}
},
handler: async (request, reply) => {
const name = request.query.[3];
return { greeting: `Hello, ${name}!` };
}
});The route uses HTTP GET method, requires 'name' in query string, and accesses it via request.query.name.