MyInternships.in

Express.js & REST APIs

Node.js REST API Design

A REST API models resources as URLs and uses HTTP methods for actions. Consistent nouns, correct status codes and predictable response shapes are what make an API pleasant to consume.


What is REST API Design in Node.js?

A REST API models resources as URLs and uses HTTP methods for actions. Consistent nouns, correct status codes and predictable response shapes are what make an API pleasant to consume.

REST API Design example

A consistent list response
JavaScript
res.json({
  data: jobs,
  meta: { page, limit, total, totalPages: Math.ceil(total / limit) },
});

Key points to remember

  • Use plural nouns for collections and never verbs in paths.
  • Version the API — /api/v1 — before you have external consumers.
  • Always paginate list endpoints; an unbounded list will eventually break.
  • Return the same error shape everywhere so clients can handle it once.

Conventional resource routes

MethodPathPurposeSuccess status
GET/api/jobslist, with filters and pagination200
GET/api/jobs/:idfetch one200 or 404
POST/api/jobscreate201 with Location
PUT/api/jobs/:idreplace entirely200
PATCH/api/jobs/:idupdate some fields200
DELETE/api/jobs/:idremove204

Common mistakes with REST API Design

  • Returning 200 with an error message in the body — clients cannot detect failure.
  • Endpoints named /getJobs or /createJob, which duplicate the HTTP method.

Node.js REST API Design— Interview Questions & FAQs

What is the difference between PUT and PATCH?+

PUT replaces the whole resource with the payload, so omitted fields are cleared. PATCH applies a partial update, changing only the fields you send.

Related Node.js Topics

Keep learning with these closely related lessons.

Ready to use your Node.js skills?

Find verified Node.js internships and fresher developer jobs across India.

Browse Node.js Internships