# GraphQL & gRPC — REST API Design

Source: https://www.geekswithgeeks.com/en/restapi/api-graphql-grpc

> Two other styles, and when they beat plain REST.

## GraphQL: one endpoint, exact fields

GraphQL exposes a single endpoint where the client specifies exactly which fields it wants across related resources in one query — fixing REST's **over-fetching** (unused fields) and **under-fetching** (needing several round trips) at the cost of a more complex server and caching story.

## gRPC: binary, typed, fast

gRPC calls typed functions over HTTP/2 using compact binary Protocol Buffers instead of JSON text — much faster to (de)serialize, with strict schemas and streaming built in. It's less browser-friendly and less human-readable than REST.

## When you'd reach for each

**REST**: public APIs, simple resources, wide tooling and caching support. **GraphQL**: rich UIs (mobile/web) pulling nested data from many sources with varying needs per screen. **gRPC**: service-to-service calls inside your own infrastructure where speed and strict contracts matter more than browser access.

**Quiz:** A mobile app screen needs a user's profile, their last 3 orders, and their unread notification count in one round trip, with minimal extra data. What fits best?

- [ ] Three separate REST calls
- [x] A single GraphQL query naming exactly those fields
- [ ] A gRPC streaming call

*Answer:* A single GraphQL query naming exactly those fields. GraphQL is built for exactly this: one query pulling exactly the needed fields across multiple resources, avoiding both extra round trips and unused data.
