Verified Jobs Live
Full Stack Web Development Intermediate Level ~4 min read

Compare REST APIs with GraphQL: Architectural differences, advantages, trade-offs, and when to use which.

Quick Revision Summary

REST uses multiple HTTP endpoints with native caching but suffers from over/under-fetching. GraphQL uses a single endpoint with precise client-specified payloads.

Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Model Answer & Deep-Dive Explanation

REST (Representational State Transfer):

  • Resource-oriented architecture relying on standard HTTP verbs (GET, POST, PUT, DELETE) and fixed URL endpoints.
  • Strong browser-level caching (HTTP 304, ETag).
  • Drawbacks: Over-fetching (fetching unwanted fields) and under-fetching (requiring N+1 roundtrips to retrieve nested associations).

GraphQL:

  • Query-oriented architecture where clients query a single POST endpoint requesting exact schema fields.
  • Solves over-fetching and under-fetching in a single request.
  • Drawbacks: Complex caching (cannot easily rely on URL-based HTTP caching), complex query parsing overhead, vulnerability to malicious nested queries.

Interviewer Evaluation Points & Scoring Rubric

  • 1 1. Highlights over-fetching and under-fetching issues. 2. Discusses HTTP caching in REST vs GraphQL complexity. 3. Recommends appropriate architectural choice.