Skip to content
Learn Netverks

Lesson

Step 22/36 61% through track

json-apis

Building JSON APIs

Last reviewed May 28, 2026 Content v20260528
Track mode
nodejs_server
Means
Node sandbox
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Building JSON APIs: the syntax, APIs, and habits you need before advancing in Node.js.

Teams ship Building JSON APIs on every Node.js codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Building JSON APIs in contexts like: REST/GraphQL APIs, BFF layers, CLIs, webhooks, and real-time services (with WebSockets).

Run JavaScript on the Node runner when configured—never mix arbitrary shell commands in lessons.

When you can explain the previous lesson's ideas without copying starter code.

Most Node backends expose JSON REST APIs for SPAs and mobile apps—predictable URLs, HTTP verbs, and structured error payloads.

CRUD sketch

  • GET /api/items — list
  • GET /api/items/:id — detail
  • POST /api/items — create (201 + Location header)
  • PATCH /api/items/:id — partial update
  • DELETE /api/items/:id — remove (204)

Error shape

res.status(400).json({
  error: 'Validation failed',
  fields: { email: 'Invalid format' }
});

Versioning

Prefix routes (/api/v1/...) or use Accept headers—pick one team convention and document breaking changes.

Important interview questions and answers

  1. Q: REST vs GraphQL?
    A: REST uses multiple endpoints; GraphQL one endpoint with client-specified fields—Node supports both (Apollo, Mercurius).
  2. Q: Idempotent methods?
    A: GET, PUT, DELETE should be safe/repeatable; POST creates new resources—important for retries.

Self-check

  1. Which status code for successful create?
  2. Why return structured validation errors?

Tip: Always set Content-Type: application/json and use JSON.stringify—never concatenate user input into JSON strings manually.

Interview prep

REST status codes for CRUD?

GET 200, POST create 201, PUT/PATCH 200, DELETE 204; 400 bad input, 401 unauthenticated, 403 forbidden, 404 not found, 500 server error.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • REST naming habit?
  • Validation layer where?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump