> For the complete documentation index, see [llms.txt](https://petercheng7788.gitbook.io/developer-note/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://petercheng7788.gitbook.io/developer-note/web-communication/graphql/rest-api-vs-graphql.md).

# REST API vs GraphQL

## Overview

<figure><img src="https://1374779285-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MFW3x2aqEO8GF2kr3VU%2Fuploads%2Fe0s5oStZvqj7I7Khyd0n%2Fimage.png?alt=media&amp;token=915fc2bf-a6ca-4345-b1bf-0f14fa0fd8cc" alt=""><figcaption></figcaption></figure>

## Similarity

* Both make http call from client to server and response in json format

## Differences

### Rest API

* The data format and operation is defined by API route itself, each API end point have a clear definition
* Easy to cache with CDN, proxies
* Simple to make a call

### GraphQL

* The data format and operation is defined by client, The data definition is flexible
* Hard to cache
* Require time to learn, including query definition, tooling support to make call

## Discussion

* If data format is different from lots of application, there is time-wasting to develop various API end points to support different application, GraphQL is a better choice
* Otherwise, In considering common practice, learning curve, the clearness of definition, REST API is a better choice for business

## References

{% embed url="<https://www.youtube.com/watch?v=yWzKJPw_VzM>" %}
