0
0
NestJSframework~10 mins

Status codes and headers 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 201 status code in a NestJS controller method.

NestJS
return response.status([1]).send('Created');
Drag options to blanks, or click blank then click option'
A201
B200
C404
D500
Attempts:
3 left
💡 Hint
Common Mistakes
Using 200 instead of 201 for resource creation.
Using error codes like 404 or 500 by mistake.
2fill in blank
medium

Complete the code to set a custom header 'X-Custom-Header' with value 'NestJS' in the response.

NestJS
response.[1]('X-Custom-Header', 'NestJS');
Drag options to blanks, or click blank then click option'
Asend
BsetHeader
Cheader
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using send instead of set to set headers.
Using setHeader which is not a NestJS response method.
3fill in blank
hard

Fix the error in setting the status code and sending JSON response.

NestJS
return response.[1](200).json({ message: 'OK' });
Drag options to blanks, or click blank then click option'
Asend
Bstatus
Cset
Dheader
Attempts:
3 left
💡 Hint
Common Mistakes
Using send to set status code causes errors.
Using set or header instead of status.
4fill in blank
hard

Fill both blanks to set status 404 and a custom header 'X-Error' with value 'NotFound'.

NestJS
return response.[1](404).[2]('X-Error', 'NotFound').send();
Drag options to blanks, or click blank then click option'
Astatus
Bset
Cheader
Dsend
Attempts:
3 left
💡 Hint
Common Mistakes
Using header instead of set for headers.
Using send to set status code.
5fill in blank
hard

Fill all three blanks to set status 204, add header 'X-Info' with 'No Content', and send the response.

NestJS
return response.[1](204).[2]('X-Info', 'No Content').[3]();
Drag options to blanks, or click blank then click option'
Astatus
Bset
Csend
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Using json with 204 status which should have no body.
Using header instead of set.