🧠 ν’€μŠ€νƒμœΌλ‘œ μ „ν™˜: λ°±μ—”λ“œ 및 REST API ꡬ좕

λ°œν–‰: (2025λ…„ 12μ›” 26일 μ˜€ν›„ 05:26 GMT+9)
6 λΆ„ μ†Œμš”
원문: Dev.to

Source: Dev.to

Cover image for 🧠 Going Full Stack: Building the Backend & REST API

Hey fellow developers! πŸ‘‹
μ•ˆλ…•ν•˜μ„Έμš”, 개발자 μ—¬λŸ¬λΆ„! πŸ‘‹

In my last post I focused on upgrading the frontend UI and UX. It looked much better, but it still lacked the full‑stack feel of a real application. This post is all about the backend β€” where things actually started getting serious.
μ§€λ‚œ κΈ€μ—μ„œλŠ” ν”„λ‘ νŠΈμ—”λ“œ UI와 UXλ₯Ό κ°œμ„ ν•˜λŠ” 데 μ§‘μ€‘ν–ˆμŠ΅λ‹ˆλ‹€. 훨씬 보기 μ’‹μ•„μ‘Œμ§€λ§Œ μ‹€μ œ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ˜ ν’€μŠ€νƒ 감각은 아직 λΆ€μ‘±ν–ˆμ£ . 이번 글은 λ°±μ—”λ“œμ— κ΄€ν•œ λ‚΄μš©μœΌλ‘œ, 본격적으둜 μ§„μ§€ν•΄μ§€κΈ° μ‹œμž‘ν•œ λΆ€λΆ„μž…λ‹ˆλ‹€.

Why Adding a Backend Was Necessary

λ°±μ—”λ“œλ₯Ό μΆ”κ°€ν•΄μ•Ό ν–ˆλ˜ 이유

Initially I wanted a backend to practice and improve my backend skills. From the app’s perspective, a backend was essential for:
μ²˜μŒμ—” λ°±μ—”λ“œ μ‹€λ ₯을 μ—°μŠ΅ν•˜κ³  ν–₯μƒμ‹œν‚€κΈ° μœ„ν•΄ λ°±μ—”λ“œλ₯Ό λ§Œλ“€κ³  μ‹Άμ—ˆμŠ΅λ‹ˆλ‹€. μ•± μž…μž₯μ—μ„œ λ°±μ—”λ“œλŠ” λ‹€μŒκ³Ό 같은 이유둜 ν•„μˆ˜μ˜€μŠ΅λ‹ˆλ‹€:

  • πŸ“š Large amounts of quote data
  • πŸ“š λ°©λŒ€ν•œ 인용ꡬ 데이터
  • πŸ€– Future AI scalability
  • πŸ€– ν–₯ν›„ AI ν™•μž₯μ„±
  • πŸ—‚οΈ Category‑based filtering
  • πŸ—‚οΈ μΉ΄ν…Œκ³ λ¦¬ 기반 필터링

Handling all of this purely on the frontend would have been messy and unrealistic. With a backend the solution becomes clean and manageable.
이 λͺ¨λ“  μž‘μ—…μ„ ν”„λ‘ νŠΈμ—”λ“œλ§ŒμœΌλ‘œ μ²˜λ¦¬ν•œλ‹€λ©΄ λ³΅μž‘ν•˜κ³  λΉ„ν˜„μ‹€μ μΌ μˆ˜λ°–μ— μ—†μŠ΅λ‹ˆλ‹€. λ°±μ—”λ“œλ₯Ό 두면 해결책이 κΉ”λ”ν•˜κ³  κ΄€λ¦¬ν•˜κΈ° μ‰¬μ›Œμ§‘λ‹ˆλ‹€.

Backend Setup & Structure

λ°±μ—”λ“œ μ„€μ • 및 ꡬ쑰

Stack
μŠ€νƒ

  • Node.js + Express β†’ REST API
  • Node.js + Express β†’ REST API
  • MongoDB (Compass locally) β†’ Database
  • MongoDB (둜컬 Compass) β†’ λ°μ΄ν„°λ² μ΄μŠ€
  • Render β†’ Backend deployment (more on this in the next post)
  • Render β†’ λ°±μ—”λ“œ 배포 (λ‹€μŒ κΈ€μ—μ„œ μžμ„Ένžˆ λ‹€λ£Ήλ‹ˆλ‹€)

Project Structure

ν”„λ‘œμ νŠΈ ꡬ쑰

/
β”œβ”€β”€ index.html
β”œβ”€β”€ style.css
β”œβ”€β”€ script.js
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ server.js
β”‚   └── models/
β”‚       └── Quote.js
└── README.md

Schema Creation

μŠ€ν‚€λ§ˆ 생성

The core of the backend is the quote schema:
λ°±μ—”λ“œμ˜ 핡심은 인용ꡬ μŠ€ν‚€λ§ˆμž…λ‹ˆλ‹€:

const quoteSchema = new mongoose.Schema({
  text: { type: String, required: true },
  author: { type: String, required: true },
  category: { type: String, required: true }
});

How it works
λ™μž‘ 방식

  1. A category button is clicked on the frontend.
    ν”„λ‘ νŠΈμ—”λ“œμ—μ„œ μΉ΄ν…Œκ³ λ¦¬ λ²„νŠΌμ„ ν΄λ¦­ν•©λ‹ˆλ‹€.
  2. A request is sent to the backend.
    λ°±μ—”λ“œμ— μš”μ²­μ„ λ³΄λƒ…λ‹ˆλ‹€.
  3. The backend filters quotes by category.
    λ°±μ—”λ“œκ°€ μΉ΄ν…Œκ³ λ¦¬λ³„λ‘œ 인용ꡬλ₯Ό ν•„ν„°λ§ν•©λ‹ˆλ‹€.
  4. The text and author are sent back.
    ν…μŠ€νŠΈμ™€ μ €μžλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.
  5. The quote is displayed to the user.
    μΈμš©κ΅¬κ°€ μ‚¬μš©μžμ—κ²Œ ν‘œμ‹œλ©λ‹ˆλ‹€.

Connecting Backend to Frontend

λ°±μ—”λ“œμ™€ ν”„λ‘ νŠΈμ—”λ“œ μ—°κ²°

Inside script.js (formerly index.js) I created a fetchQuotes() function:
script.js(이전 index.js) μ•ˆμ— fetchQuotes() ν•¨μˆ˜λ₯Ό λ§Œλ“€μ—ˆμŠ΅λ‹ˆλ‹€:

async function fetchQuotes(category = null) {
  try {
    const url = category
      ? `${API_URL}/quotes/category/${category}`
      : `${API_URL}/quotes`;

    const res = await fetch(url);
    const quotes = await res.json();

    usedQuotes = [];
    usedColours = [];
    newQuote();
  } catch (err) {
    console.error("Backend not available:", err);
  }
}

fetchQuotes();

For now API_URL points to localhost. Later it will switch to the deployed backend URL, which leads perfectly into the next post.
ν˜„μž¬ API_URL은 localhostλ₯Ό 가리킀고 μžˆμŠ΅λ‹ˆλ‹€. μΆ”ν›„ 배포된 λ°±μ—”λ“œ URL둜 λ°”λ€” μ˜ˆμ •μ΄λ©°, μ΄λŠ” λ‹€μŒ κΈ€κ³Ό μžμ—°μŠ€λŸ½κ²Œ μ—°κ²°λ©λ‹ˆλ‹€.

Final Result (Locally)

μ΅œμ’… κ²°κ³Ό (둜컬)

Everything works perfectly on my local system:
λ‚΄ 둜컬 ν™˜κ²½μ—μ„œ λͺ¨λ“  것이 μ™„λ²½νžˆ λ™μž‘ν•©λ‹ˆλ‹€:

  • Quotes are fetched from the backend.
    μΈμš©κ΅¬κ°€ λ°±μ—”λ“œμ—μ„œ κ°€μ Έμ™€μ§‘λ‹ˆλ‹€.
  • Categories are filtered correctly.
    μΉ΄ν…Œκ³ λ¦¬κ°€ μ˜¬λ°”λ₯΄κ²Œ ν•„ν„°λ§λ©λ‹ˆλ‹€.
  • No more hard‑coded data.
    ν•˜λ“œμ½”λ”©λœ 데이터가 더 이상 μ—†μŠ΅λ‹ˆλ‹€.

All that’s left is deployment.
이제 남은 것은 λ°°ν¬λΏμž…λ‹ˆλ‹€.

What’s Coming Next

λ‹€μŒμ— λ‹€λ£° λ‚΄μš©

In the next post I’ll cover:
λ‹€μŒ κΈ€μ—μ„œλŠ” λ‹€μŒμ„ λ‹€λ£° μ˜ˆμ •μž…λ‹ˆλ‹€:

  • 🌐 Frontend deployment β†’ GitHub Pages
  • 🌐 ν”„λ‘ νŠΈμ—”λ“œ 배포 β†’ GitHub Pages
  • ☁️ Backend deployment β†’ Render
  • ☁️ λ°±μ—”λ“œ 배포 β†’ Render
  • πŸ§ͺ Live‑data debugging
  • πŸ§ͺ μ‹€μ‹œκ°„ 데이터 디버깅
  • πŸ”„ MongoDB Compass β†’ MongoDB Atlas
  • πŸ”„ MongoDB Compass β†’ MongoDB Atlas

Stay tuned for the next update! πŸ˜„πŸ”₯
λ‹€μŒ μ—…λ°μ΄νŠΈλ₯Ό κΈ°λŒ€ν•΄ μ£Όμ„Έμš”! πŸ˜„πŸ”₯

Back to Blog

κ΄€λ ¨ κΈ€

더 보기 Β»

텔루ꡬ어 Java Full Stack μ½”μŠ€ Reloaded: ν˜„λŒ€ 개발자λ₯Ό μœ„ν•œ μ™„μ „ ν•™μŠ΅ κ°€μ΄λ“œ

μ†Œν”„νŠΈμ›¨μ–΄ 산업은 κ·Έ μ–΄λŠ λ•Œλ³΄λ‹€ λΉ λ₯΄κ²Œ μ§„ν™”ν•˜κ³  있으며, 그와 ν•¨κ»˜ 전체 μ• ν”Œλ¦¬μΌ€μ΄μ…˜ κ°œλ°œμ„ μ²˜λ¦¬ν•  수 μžˆλŠ” λ‹€μž¬λ‹€λŠ₯ν•œ κ°œλ°œμžμ— λŒ€ν•œ μˆ˜μš”κ°€ μ¦κ°€ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€.

Laravel 12μ—μ„œ ν˜„λŒ€μ μΈ API κ°œλ°œμ„ μœ„ν•œ μ™„μ „ κ°€μ΄λ“œ

μ†Œκ°œ μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ΄ 규λͺ¨λ₯Ό ν™•λŒ€ν•¨μ— 따라 κ²¬κ³ ν•˜κ³  μ•ˆμ „ν•˜λ©° μœ μ§€ 관리가 κ°€λŠ₯ν•œ API에 λŒ€ν•œ ν•„μš”μ„±μ΄ κΈ‰κ²©νžˆ μ¦κ°€ν•©λ‹ˆλ‹€. 이 κΈ°μ‚¬μ—μ„œλŠ” Laravel 12κ°€ νŠΉλ³„ν•œ μ΄μœ μ™€β€¦