0
0
NestJSframework~10 mins

Response handling in NestJS - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Ajson
BsendFile
Credirect
Drender
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
2fill in blank
medium

Complete 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'
Astatus
Bsend
Ccode
DsetStatus
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
3fill in blank
hard

Fix 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'
AsendStatus
Bstatus
Csend
Djson
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
4fill in blank
hard

Fill 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'
AsetHeader
Bjson
Csend
Dheader
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
5fill in blank
hard

Fill 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'
Astatus
BsendFile
Ctype
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.json to send files
Setting content type after sending response
Not chaining methods properly