100% found this document useful (1 vote)
152 views

GraphQL Vs RestAPI

GraphQL and REST APIs have key differences in their structure, flexibility, and efficiency. GraphQL uses a single endpoint and queries to request specific data, while REST has fixed endpoints representing resources. GraphQL is more flexible as clients request exact data needs, and can be more efficient by fetching all data in one request, while REST may require multiple requests. Caching is easier for REST but GraphQL responses are tailored to queries. Both have tradeoffs in data fetching and evolving APIs.

Uploaded by

Musammat Samina
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
152 views

GraphQL Vs RestAPI

GraphQL and REST APIs have key differences in their structure, flexibility, and efficiency. GraphQL uses a single endpoint and queries to request specific data, while REST has fixed endpoints representing resources. GraphQL is more flexible as clients request exact data needs, and can be more efficient by fetching all data in one request, while REST may require multiple requests. Caching is easier for REST but GraphQL responses are tailored to queries. Both have tradeoffs in data fetching and evolving APIs.

Uploaded by

Musammat Samina
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

brijpandeyji

GraphQL

vs

REST API
Know the
difference!!
swipe
brijpandeyji

GraphQL
GraphQL is a query language for
your API, as well as a runtime for
executing those queries against
your data.
Developed
Developed byby Facebook
Facebook and
and
released
released in
in 2015
2015

REST API
It is an architecture style to
develop web applications. It uses
HTTP protocol as a
communication interface.
Introduced
Introduced by
by Roy
Roy Fielding
Fielding
in
in 2000
2000

The biggest difference between GraphQL and REST is the manner in which data
is sent to the client. In a REST architecture, the client makes an HTTP request
and data is sent as an HTTP response, while in GraphQL, the client requests data
with queries.

swipe
brijpandeyji

The key differences


between GraphQL and
REST are based on the 7 Differences
following.

Structure
2
Flexibility
3

Efficiency
4

Caching
5

Data Fetching
6

API Evolution
7

Versioning

swipe
brijpandeyji

Structure Based on
endpoints, request
and response

GraphQL
GraphQL APIs, have a single
endpoint that is used to query,
mutate, and subscribe to data.

Uses query or mutation to request


data.
Request and Response
Server responds based on the
request query.

REST APIs have a fixed set of REST API


endpoints, each representing a
specific resource.

Uses HTTP methods to request


data.

Response based on the endpoint Request and Response


being called.

swipe
brijpandeyji

Flexibility

GraphQL
GraphQL allows clients to request
exactly the data they need, in a
single request.

More Flexible

REST API
REST APIs are typically more rigid
and require multiple requests to
retrieve all the data needed for a
particular use case.

Less Flexible

swipe
brijpandeyji

Efficiency

GraphQL
GraphQL can be more efficient
than REST because it allows the
client to request all the data it
needs in a single request.

Reduces the number of round trips to the


server, thus improving efficiency.

REST API
It is less efficient than GraphQL as
it may need to make multiple
requests to different endpoints to
retrieve the data needed.

Efficient at times where there are large number


of small, specific requests.
Efficiency of an API
depends on the specific
needs of the client and
Both can be efficient the use case.

swipe
brijpandeyji

Caching
It is a technique used to improve the
performance of an API by reducing
the number of requests made to the
server.

GraphQL
In GraphQL, the response is
tailored to the specific request, so
it is more difficult to cache.

REST API
REST APIs can be cached more
easily, as the response from a
specific endpoint will always be
the same.
Note

While
While caching
caching can
can improve
improve performance,
performance, itit can
can also
also lead
lead to
to
outdated
outdated or
or stale
stale data
data being
being served
served to
to clients
clients ifif the
the cache
cache is
is
not
not properly
properly invalidated
invalidated or
or refreshed.
refreshed.

swipe
brijpandeyji

Data Fetching

GraphQL
With GraphQL, the client can
request exactly the data it needs,
reducing the amount of data
transferred over the network.

REST API
REST APIs can sometimes suffer
from over fetching or under
fetching, where the client receives
more or less data than it needs.

Note

GraphQL and REST each have their own approaches to


addressing these issues.

swipe
brijpandeyji

API Evolution

GraphQL
In GraphQL, the API can evolve
more flexibly, as the client can
request only the fields it needs
and ignore the rest.

Can add new fields and types without


breaking existing clients.

REST API
In a REST API, adding a new field
or endpoint requires a new
version of the API. This makes API
evolution harder.

Must use versioning to ensure that


the existing clients do not break.
Needs
Needs to
to be
be supported
supported and
and maintained
maintained

swipe
brijpandeyji

Versioning

GraphQL
GraphQL APIs do not require
versioning because the client can
request any combination of fields.

In a GraphQL API, versioning


can be implemented by creating
a new schema for each version
of the API.

REST API
REST APIs typically require
versioning when the shape of the
data changes.

In a REST API, versioning can


be implemented by using a
different URL for each version
of the API.

swipe
brijpandeyji

Conclusion

Overall

GraphQL
GraphQL and
and REST
REST are
are both
both
useful
useful tools
tools for
for building
building APIs,
APIs,
and
and which
which one
one you
you choose
choose
depends
depends on
on the
the specific
specific needs
needs
of
of your
your project.
project.

You now know the


differences between
a GraphQL API and a
REST API.

You might also like