GraphQL

One endpoint where the client writes a query naming exactly the fields it wants, and gets back JSON shaped like that query.

ask for only the fields I wantone endpoint for everythinggraph qlgraphglquery language for apisthe api with the playgroundshape the response myselfthe alternative to REST

See it

Live demo coming soon

What it is

GraphQL replaces a pile of URLs with one endpoint and a typed schema. The client sends a query that names the exact fields it wants, including nested ones, and the response comes back shaped like the query. Reads are queries, writes are mutations, live updates are subscriptions, and every field is backed by a resolver function on the server. GitHub, Shopify, and Linear all ship one.

Reach for it when several different clients need different slices of the same graph, or when a screen currently needs four REST calls stitched together. The schema doubles as documentation and gives you generated TypeScript types for free (graphql-codegen), which is half the appeal in practice.

Two real costs. The N+1 problem: a query for 50 posts and their authors naively fires 51 database calls, which is what DataLoader batching exists to fix. And caching gets less automatic. Clients usually POST every operation to a single URL, and a POST body is not a cache key, so the free HTTP and CDN caching you get from REST mostly does not apply out of the box. You can win some of it back by sending read-only queries over GET, or by using persisted queries so each operation has a short stable cacheable URL, but most teams lean on a client cache like Apollo or urql instead. A public GraphQL endpoint also lets strangers write brutally expensive nested queries, so add depth limits, cost analysis, or persisted queries before you open it up.

Ask AI for it

Build a GraphQL API for this data model. Define a typed SDL schema with Query, Mutation, and the entity types plus their relations, implement resolvers, and wire it up with GraphQL Yoga (or Apollo Server) at /graphql. Batch every relation lookup through DataLoader to avoid N+1 queries, add a query depth limit of 7, and expose the schema to graphql-codegen so the client gets generated TypeScript hooks. Include one example query and one example mutation with variables.

You might have meant

rest apiendpointpayloadgrpcopenapi specification

Go deeper