Skip to content
engineering workbench.by StudyPort Academy
Learning path
Intermediate16 min

Request and response basics

Understand the idea

Read the JSON body, choose a status, and send JSON back once.

The idea

express.json() is that parses a JSON onto req.body. res.status(201).json(...) sets the status and writes the . JSON here is the text format both sides already share.

What changes

Body in and JSON out
CallEffectIf you skip it
express.json()req.body is an objectreq.body stays empty
res.status(201)Status is 201 CreatedStatus stays 200
res.json(object)One JSON bodyA second send throws

The command

Save a title

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

The mistake

Check the result

Status 201 and a JSON body whose saved field is Milk.

Guided challenge

Create with status 201

POST /notes currently answers with 200. Change it so a successful create returns 201 and the saved title.

Create with status 201

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

EXPECTED RESULT

status 201
{"saved":"Milk"}

Hints 0/2

    Use all hints or make 3 failed checks (0/3).

    Free exploration

    Change this example and run it again. Each run is a new process. Nothing is saved.

    Your variation

    3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01What puts the JSON on req.body?
    02How many responses can one request have?

    Ready to call this one understood?

    Mark this lesson complete to earn 150 XP. You can always revisit it.

    Sign in to save progress
    Next lesson