0Pricing
Node.js Backend Development Bootcamp · Lesson

Handling Request Data: Body, Query & Params

Master how Express receives and parses incoming data from clients, including route parameters, query strings, JSON bodies, and form submissions.

Handling Request Data: Body, Query & Params is a free Node.js Backend Development Bootcamp lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Node.js Backend Development Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Where Client Data Comes From

An HTTP request can carry data in several places. An Express handler reads each from a different property of the req object:

  • Route params: req.params
  • Query string: req.query
  • Request body: req.body
  • Headers: req.headers
app.get('/info', (req, res) => {
  res.json({ params: req.params, query: req.query });
});

Route Parameters

Route parameters are named URL segments prefixed with a colon. For /users/:id, a request to /users/42 gives req.params.id === '42'.

They are always strings, so convert to numbers when needed.

app.get('/users/:id', (req, res) => {
  const id = Number(req.params.id);
  res.send('Looking up user ' + id);
});

Multiple Route Parameters

A route can capture several params at once. Each colon segment becomes a key on req.params.

app.get('/books/:author/:title', (req, res) => {
  const { author, title } = req.params;
  res.send(author + ' wrote ' + title);
});

Query Strings

Everything after the ? in a URL is the query string. Express parses it into req.query as key-value pairs.

For /search?term=node&page=2, you get req.query.term and req.query.page.

app.get('/search', (req, res) => {
  const { term, page } = req.query;
  res.send('Searching ' + term + ' page ' + (page || 1));
});

Parsing JSON Bodies

POST and PUT requests usually send a JSON body. Express does not parse it by default — you must enable the built-in middleware express.json().

const express = require('express');
const app = express();
app.use(express.json());
app.post('/users', (req, res) => {
  res.json({ received: req.body });
});

Parsing Form Data

HTML forms submit data as application/x-www-form-urlencoded. Enable express.urlencoded() to populate req.body from form fields.

app.use(express.urlencoded({ extended: true }));
app.post('/login', (req, res) => {
  res.send('Welcome ' + req.body.username);
});

Validating Required Fields

Never trust client input. Always check that required fields are present before using them, and respond with a 400 Bad Request if something is missing.

app.post('/users', (req, res) => {
  const { name, email } = req.body;
  if (!name || !email) {
    return res.status(400).json({ error: 'name and email required' });
  }
  res.status(201).json({ name, email });
});

Reading Headers

Headers carry metadata like authentication tokens and content types. Access them via req.headers (keys are lowercased) or the helper req.get().

app.get('/secure', (req, res) => {
  const auth = req.get('Authorization');
  res.send('Token: ' + (auth || 'none'));
});

Default Values for Optional Data

Query and body values are often optional. Provide sensible defaults so your handler does not break when a parameter is omitted.

app.get('/products', (req, res) => {
  const page = Number(req.query.page) || 1;
  const limit = Number(req.query.limit) || 10;
  res.json({ page, limit });
});

Combining All Three Sources

A single endpoint can read params, query, and body together. For example, updating a resource identified by a param, with options in the query, and new data in the body.

app.put('/users/:id', (req, res) => {
  const id = req.params.id;
  const notify = req.query.notify === 'true';
  const updates = req.body;
  res.json({ id, notify, updates });
});

Common Mistakes

Watch out for these pitfalls:

  • Forgetting express.json() so req.body is undefined
  • Treating params as numbers without converting
  • Trusting input without validation
  • Confusing query (?key=value) with params (/:key)

Quick Check

Test your knowledge of Express request data.

Recap

You now know how Express receives client data:

  • req.params for named URL segments
  • req.query for the query string
  • req.body for JSON (with express.json()) and forms (with express.urlencoded())
  • req.headers / req.get() for metadata

Always validate and provide defaults — never trust raw client input.

Frequently asked questions

Is the “Handling Request Data: Body, Query & Params” lesson free?

Yes — the full text of “Handling Request Data: Body, Query & Params” is free to read here on the web, and the Node.js Backend Development Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Node.js Backend Development Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “Handling Request Data: Body, Query & Params”?

Master how Express receives and parses incoming data from clients, including route parameters, query strings, JSON bodies, and form submissions. You practise Node.js Backend Development Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Node.js Backend Development Bootcamp?

No prior experience is required. Node.js Backend Development Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Handling Request Data: Body, Query & Params” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Node.js Backend Development Bootcamp lesson?

Yes. Every Node.js Backend Development Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Express.js Framework Fundamentals
  2. Routing & Middleware in Express
  3. Designing RESTful API Endpoints
  4. Handling Request Data: Body, Query & Params
← Back to Node.js Backend Development Bootcamp