Recall & Review
beginner
What is the purpose of using JSON in Express request and response?
JSON is used to send and receive data in a simple, text-based format that both client and server can easily understand and parse.
Click to reveal answer
beginner
How do you parse JSON data sent in a POST request in Express?
Use the built-in middleware express.json() to automatically parse incoming JSON request bodies and make the data available in req.body.
Click to reveal answer
beginner
Which method sends a JSON response in Express?
The res.json() method sends a JSON response. It converts a JavaScript object or array into JSON and sets the Content-Type header to application/json.
Click to reveal answer
intermediate
Why should you set Content-Type to application/json in Express responses?
Setting Content-Type to application/json tells the client that the response body contains JSON data, so the client can parse it correctly.
Click to reveal answer
intermediate
What happens if you forget to use express.json() middleware when sending JSON in a POST request?
Without express.json(), Express won't parse the JSON body, so req.body will be undefined or empty, making it impossible to access the sent data.
Click to reveal answer
Which Express middleware is used to parse JSON request bodies?
✗ Incorrect
express.json() parses incoming JSON request bodies and makes the data available in req.body.
How do you send a JSON response in Express?
✗ Incorrect
res.json() converts a JavaScript object to JSON and sends it with the correct Content-Type header.
What header does Express set automatically when using res.json()?
✗ Incorrect
res.json() sets Content-Type to application/json to indicate the response contains JSON data.
If you forget to use express.json() middleware, what will req.body be for JSON POST requests?
✗ Incorrect
Without express.json(), Express does not parse the JSON body, so req.body is undefined or empty.
Which method would you use to parse URL-encoded form data in Express?
✗ Incorrect
express.urlencoded() parses URL-encoded form data, not JSON.
Explain how to handle JSON data in an Express POST request and send a JSON response.
Think about middleware and response methods for JSON.
You got /4 concepts.
Describe what happens if you send JSON data to an Express server without using express.json() middleware.
Focus on request body parsing.
You got /4 concepts.