Over the past decade, REST has become the standard (yet a fuzzy one) for designing web APIs. It offers some great ideas, such as stateless servers and structured access to resources. However, REST APIs have shown to be too inflexible to keep up with the rapidly changing requirements of the clients that access them.
XpertSolvers: Your Partner in Building Innovative Software Solutions
Graph ql vs rest
1. GraphQL vs REST
M I H A I T H E O D O R E N E S C U | M I H A I @ A M E R O M N E T W O R K . C O M | + 1 8 1 8 3 5 0 9 9 5 7
S O F T W A R E E N G I N E E R / C O A C H
2. REST API
REPRESENTATIONAL STATE TRANSFER
• HTTP verbs(GET, POST, PUT, DELETE)
• Resource Based URLs –Endpoints (/characters/34)
• In a REST Based Architecture, everything is a resource
3. REST API DESIGN
- It represent the state of database at a time.
- REST is an architectural style which is based on web-
standards and the HTTP protocol
- In a REST based architecture everything is a Resource
4. HTTP Methods
H T T P M E T H O D S T H E P U T , G E T , P O S T A N D D E L E T E M E T H O D S A R E T Y P I C A L L Y U S E D I N R E S T B A S E D A R C H I T E C T U R E S .
HTTP Method CRUD Operation Description
POST INSERT Adds an existing
resource
PUT UPDATE Overrides an existing
resource
GET SELECT Fetches a resource
DELETE DELETE Deletes a resource
5. GraphQL – A
query
language for
APIs
IT’S THE RESPONSIBILITY OF
THE API TO PROVIDE AN
INTERFACE TO THE STORED
DATA THAT FITS AN
APPLICATION’S NEEDS.
6. Find using REST
FIND A MOVIE USING RESTFUL API
But what if you want to find
actors/characters in the movie?
According to REST Standards you will
need to have multiple endpoints.
I will show in the next slide…
8. Find using REST
FIND A MOVIE USING RESTFUL API
# 4 different queries
1. GET /movies/14
2. GET /movies/14/characters
3. GET /character/34
4. GET /character/35
# 1 Request ‐ Add boolean query string
GET /movies/1?include_character_details=true
# 1 Request ‐ New custom endpoint
GET /movies_with_character_details/1
11. GraphQL Goals
WHAT MAY BE THE ADVANTAGE HERE?
- Eliminate Over-fetching
- Eliminate Under-fetching
- Be Declarative
- Increase Product Developer Autonomy
- Natively Support Versioning
18. GraphQL Advantages
WHAT MAKES IT FLEXIBLE?
- User-Defined typesystem - "schema"
- Data Universe is defined and connected on the server
- Multiple Back-end services exposed through a single controlled API
- The client requests for exactly what it wants