0
0
Expressframework~10 mins

POST route handling 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 create a POST route for '/submit'.

Express
app.[1]('/submit', (req, res) => {
  res.send('Form submitted');
});
Drag options to blanks, or click blank then click option'
Aget
Bpost
Cput
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'post' for form submission routes.
Using 'put' or 'delete' which are for other HTTP actions.
2fill in blank
medium

Complete the code to access JSON data sent in the POST request body.

Express
app.post('/data', (req, res) => {
  const userData = req.[1];
  res.json(userData);
});
Drag options to blanks, or click blank then click option'
Aparams
Bheaders
Cquery
Dbody
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'params' which is for URL parameters.
Using 'query' which is for URL query strings.
3fill in blank
hard

Fix the error in the code to parse JSON body data correctly.

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

app.[1](express.json());

app.post('/info', (req, res) => {
  res.send(req.body);
});
Drag options to blanks, or click blank then click option'
Ause
Bpost
Clisten
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'use' for middleware.
Not adding JSON parsing middleware at all.
4fill in blank
hard

Fill both blanks to send a JSON response with a status code 201.

Express
app.post('/create', (req, res) => {
  res.[1](201).[2]({ message: 'Created' });
});
Drag options to blanks, or click blank then click option'
Astatus
Bjson
Csend
Dend
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send' instead of 'json' for JSON responses.
Not setting the status code properly.
5fill in blank
hard

Fill all three blanks to create a POST route that reads JSON body, logs it, and responds with a success message.

Express
app.[1]('/log', (req, res) => {
  const data = req.[2];
  console.log(data);
  res.[3]({ status: 'success' });
});
Drag options to blanks, or click blank then click option'
Apost
Bbody
Cjson
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'post' for the route.
Trying to access data from 'params' or 'query' instead of 'body'.
Using 'send' instead of 'json' for the response.