Comparative Study: RESTful vs. GraphQL Architectures for GitHub APIs
Published: 2024-03-03 18:15:13

In this study, I compare the performance, flexibility, and client experience of RESTful and GraphQL architectures for GitHub APIs.

**Architecture Selection**
I selected GitHub APIs implemented in RESTful principles and GraphQL query language to ensure a fair comparison.

**Performance Testing**
As part of my performance testing, I measured the time it takes to fetch repositories from IBM, as well as the time it takes to create and delete repositories using both APIs.

_Fetching Repositories:_


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y4fy7kfninv1nqtbf9bs.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ec3w17qua25pl1pvz7p.png)

As we can see
REST fetched 700 repositories in 10.719 seconds.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nl16wwtuovesi2brn5im.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7q89hkzrdpmyw0sez2wz.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lseznh2ehvizkevj19ev.png)

And GraphQL fetched 900 repositories in 10.345 seconds.

_Creating and Deleting Repositories:_

my usage
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aota8heepb6p5yl8yqlm.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gu3s06cbxzj67jiuhedl.png)
REST created 15 repositories in 16.887 seconds and deleted them in 9.311 seconds.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jz7wgqmbu4fnuem0exhl.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3qfpxf1xmtkj60zl7jzk.png)

GraphQL created 15 repositories in 16.040 seconds. But, unfortunately, had no support for deleting.

**Flexibility and Extensibility**

With RESTful APIs, adding features and modifying endpoints can be straightforward, especially for developers familiar with RESTful principles. Endpoints are typically designed to represent resources and actions, making it intuitive to add new resources or modify existing ones. However, as requirements evolve, RESTful APIs may face challenges such as endpoint proliferation or the need to version endpoints to maintain backward compatibility.

In contrast, GraphQL offers a more flexible approach to adding features and modifying endpoints. Its single endpoint allows clients to request precisely the data they need, eliminating the need to create multiple endpoints for different use cases. This simplifies the process of adding new features or modifying existing ones, as developers can extend the GraphQL schema to accommodate new requirements without impacting existing clients.

**Evaluation and Recommendations**

While both architectures offer capabilities for accommodating evolving requirements, GraphQL's flexibility and ease of schema evolution provide a significant advantage in adapting to changing needs. With RESTful APIs, careful planning and versioning strategies may be necessary to manage endpoint complexity and ensure backward compatibility as requirements evolve.

It's worth noting that RESTful APIs are older and much more familiar in the industry, which can be advantageous in terms of developer familiarity and tooling support.