REST — multiple endpoints, fixed data structure. GraphQL — single endpoint, client-specified data.
REST:
1@RestController2class UserController {3 @GetMapping("/users/{id}")4 User getUser(@PathVariable Long id) {5 return userService.findById(id);6 }7}
GraphQL:
1type Query {2 user(id: ID!): User3}4type User {5 id: ID!6 name: String!7 posts: [Post!]8}
When to use: