0
0
Expressframework~10 mins

req.body for request payload in Express - Interactive Code Practice

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

Complete the code to access the request payload in an Express POST route.

Express
app.post('/submit', (req, res) => {
  const data = req.[1];
  res.send(data);
});
Drag options to blanks, or click blank then click option'
Aparams
Bbody
Cquery
Dheaders
Attempts:
3 left
💡 Hint
Common Mistakes
Using req.params or req.query instead of req.body
Forgetting to use middleware to parse the body
2fill in blank
medium

Complete the code to parse JSON request bodies in Express.

Express
app.use(express.[1]());
Drag options to blanks, or click blank then click option'
Aurlencoded
Braw
Cstatic
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Using express.urlencoded() for JSON data
Not adding any middleware to parse the body
3fill in blank
hard

Fix the error in accessing the request payload property.

Express
app.post('/data', (req, res) => {
  const info = req.[1];
  res.json(info);
});
Drag options to blanks, or click blank then click option'
Abody
BBody
Cbodys
Dpayload
Attempts:
3 left
💡 Hint
Common Mistakes
Using uppercase 'Body' instead of 'body'
Using non-existent properties like 'bodys' or 'payload'
4fill in blank
hard

Fill both blanks to create a POST route that reads JSON data and sends a confirmation.

Express
app.post('/submit', express.[1](), (req, res) => {
  const userData = req.[2];
  res.send('Received');
});
Drag options to blanks, or click blank then click option'
Ajson
Bbody
Curlencoded
Dparams
Attempts:
3 left
💡 Hint
Common Mistakes
Using urlencoded middleware for JSON data
Accessing req.params instead of req.body
5fill in blank
hard

Fill all three blanks to create an Express app that parses URL-encoded data and accesses it in a POST route.

Express
const express = require('express');
const app = express();

app.use(express.[1]({ extended: [2] }));

app.post('/form', (req, res) => {
  const formData = req.[3];
  res.json(formData);
});
Drag options to blanks, or click blank then click option'
Ajson
Btrue
Cbody
Durlencoded
Attempts:
3 left
💡 Hint
Common Mistakes
Using express.json() middleware for URL-encoded data
Setting extended option to false when true is needed
Accessing req.params or req.query instead of req.body