0
0
Node.jsframework~10 mins

Why REST design principles matter in Node.js - Test Your Understanding

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

Complete the code to create a simple GET endpoint using Express that returns a welcome message.

Node.js
app.[1]('/welcome', (req, res) => {
  res.send('Welcome to our API!');
});
Drag options to blanks, or click blank then click option'
Aget
Bput
Cpost
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of GET for retrieving data.
Confusing HTTP methods and their purposes.
2fill in blank
medium

Complete the code to parse JSON request bodies in Express using middleware.

Node.js
app.use([1].json());
Drag options to blanks, or click blank then click option'
Acors
BbodyParser
Crouter
Dexpress
Attempts:
3 left
💡 Hint
Common Mistakes
Using bodyParser which is deprecated in newer Express versions.
Trying to use unrelated middleware like cors.
3fill in blank
hard

Fix the error in the route handler to correctly send a JSON response with a status code.

Node.js
app.get('/data', (req, res) => {
  res.status([1]).json({ message: 'Data fetched' });
});
Drag options to blanks, or click blank then click option'
A'OK'
B'200'
C200
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Passing status code as a string instead of a number.
Using status text like 'OK' instead of numeric code.
4fill in blank
hard

Fill both blanks to create a RESTful route that updates a user by ID using the correct HTTP method and URL pattern.

Node.js
app.[1]('/users/[2]', (req, res) => {
  // update user logic
  res.send('User updated');
});
Drag options to blanks, or click blank then click option'
Aput
Bpost
C:id
DuserId
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of PUT for updates.
Using incorrect parameter names without colon.
5fill in blank
hard

Fill all three blanks to create a RESTful DELETE route that removes a product by its ID and sends a confirmation message.

Node.js
app.[1]('/products/[2]', (req, res) => {
  const productId = req.params.[3];
  // delete product logic
  res.send(`Product ${productId} deleted`);
});
Drag options to blanks, or click blank then click option'
Adelete
B:id
Cid
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of DELETE.
Mismatching parameter names in URL and req.params.