Understand how to build an HTTP API without Express or any routing framework.
- A server using Node http.createServer
- Manual URL and method routing
- JSON responses with explicit status codes
- Request-body parsing for POST and PUT
Frameworks are excellent, but they hide mechanics. Knowing the baseline gives you:
- better debugging ability
- stronger performance intuition
- confidence when abstractions fail
See implementation in ../server.js.
Key areas to inspect:
- server creation
- route matching (/tasks and /tasks/:id)
- parseJSON helper
- sendResponse helper
Incoming HTTP body data arrives as stream chunks.
Server-side flow:
- listen to data events
- append chunks to a string
- on end event, parse JSON
- handle parse errors cleanly
This teaches why request parsing middleware exists in frameworks.
Think of each request like a letter arriving in pieces:
- chunk 1: envelope fragment
- chunk 2: main letter
- chunk 3: signature
You only understand the message when all pieces arrive.
- assuming body arrives all at once
- not handling malformed JSON
- forgetting proper content-type response headers
- mixing route parsing logic with business logic
Add a new endpoint:
- GET /health -> { status: "ok", uptime: number }
Rules:
- do not use external libraries
- return application/json
- keep route style consistent with existing server
Even with frameworks, production incidents often involve:
- malformed payload handling
- wrong status code semantics
- route collision edge cases
Raw-server knowledge shortens incident response time significantly.