0Pricing
Node.js Backend Development Bootcamp · 강의

요청 데이터 처리: 본문, 쿼리 및 매개변수

Express가 라우트 매개변수, 쿼리 문자열, JSON 본문, 폼 제출을 비롯한 클라이언트의 수신 데이터를 받거나 분석하는 방법을 익힙니다.

요청 데이터 처리: 본문, 쿼리 및 매개변수은(는) CoddyKit의 무료 Node.js Backend Development Bootcamp 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Node.js Backend Development Bootcamp 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Node.js Backend Development Bootcamp 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

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.

자주 묻는 질문

“요청 데이터 처리: 본문, 쿼리 및 매개변수” 강의는 무료인가요?

네 — “요청 데이터 처리: 본문, 쿼리 및 매개변수” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Node.js Backend Development Bootcamp 강의 전체를 잠금 해제할 수 있습니다. Node.js Backend Development Bootcamp 강의에는 총 4개의 강의가 포함되어 있습니다.

“요청 데이터 처리: 본문, 쿼리 및 매개변수”에서 뭘 배우나요?

Express가 라우트 매개변수, 쿼리 문자열, JSON 본문, 폼 제출을 비롯한 클라이언트의 수신 데이터를 받거나 분석하는 방법을 익힙니다. 브라우저에서 직접 실행하는 실습 코드로 Node.js Backend Development Bootcamp을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Node.js Backend Development Bootcamp을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Node.js Backend Development Bootcamp은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“요청 데이터 처리: 본문, 쿼리 및 매개변수” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Node.js Backend Development Bootcamp 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Node.js Backend Development Bootcamp 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. Express.js 프레임워크 기초
  2. Express의 라우팅과 미들웨어
  3. RESTful API 엔드포인트 설계
  4. 요청 데이터 처리: 본문, 쿼리 및 매개변수
← Node.js Backend Development Bootcamp(으)로 돌아가기