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— listGET /api/items/:id— detailPOST /api/items— create (201 + Location header)PATCH /api/items/:id— partial updateDELETE /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
- Q: REST vs GraphQL?
A: REST uses multiple endpoints; GraphQL one endpoint with client-specified fields—Node supports both (Apollo, Mercurius). - Q: Idempotent methods?
A: GET, PUT, DELETE should be safe/repeatable; POST creates new resources—important for retries.
Self-check
- Which status code for successful create?
- 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.