Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to send a JSON response with NestJS.
NestJS
return res.[1]({ message: 'Hello World' });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.sendFile instead of res.json
Using res.redirect which sends a redirect response
Using res.render which renders a template
✗ Incorrect
Use res.json() to send a JSON response in NestJS.
2fill in blank
mediumComplete the code to set the HTTP status code to 201 before sending the response.
NestJS
return res.[1](201).json({ success: true });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.send to set status code
Using res.code which does not exist
Using res.setStatus which is not a method
✗ Incorrect
Use res.status() to set the HTTP status code in NestJS.
3fill in blank
hardFix the error in sending a plain text response with status 200.
NestJS
return res.[1](200).[2]('Success');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.sendStatus which sends status and ends response immediately
Using res.json to send plain text
Not chaining status and send properly
✗ Incorrect
Use res.status(200).send('Success') to set status and send plain text.
4fill in blank
hardFill both blanks to set a custom header and send a JSON response.
NestJS
return res.[1]('X-Custom-Header', 'NestJS').[2]({ data: 'value' });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.setHeader which is not available on response object in NestJS
Using res.send instead of res.json for JSON data
Setting headers after sending response
✗ Incorrect
Use res.header() to set headers and res.json() to send JSON.
5fill in blank
hardFill all three blanks to send a file with status 200 and a custom content type.
NestJS
return res.[1](200).[2]('file.pdf').[3]('application/pdf');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.json to send files
Setting content type after sending response
Not chaining methods properly
✗ Incorrect
Use res.status() to set status, res.sendFile() to send file, and res.type() to set content type.