-
Notifications
You must be signed in to change notification settings - Fork 1
Rest vs Qraphql
Adarshtheki edited this page Jun 9, 2025
·
1 revision
REST API is an architectural style for designing networked applications. It's a lightweight, flexible, and scalable way to communicate between systems, allowing data exchange and manipulation.
-
HTTP Methods:
- GET (Retrieve resource)
- POST (Create resource)
- PUT (Update resource)
- DELETE (Delete resource)
- PATCH (Partial update resource)
-
REST API Components:
-
Resource: Identified by URI (Uniform Resource Identifier) -
Request: Client sends HTTP request to server -
Response: Server sends HTTP response to client -
Header: Metadata about request/response (e.g., authentication, content type) -
Body: Payload of request/response (e.g., JSON data)
-
-
REST API Status Codes:
-
200OK (successful request) -
404Not Found (resource not found) -
401Unauthorized (authentication failed) -
500Internal Server Error (server error)
-
GraphQL is a query language for APIs (Application Programming Interfaces) that allows clients to specify exactly what data they need, reducing overhead and improving performance.
-
Key Features:
- Declarative queries
- Strong typing
- Schema-driven development
- Query optimization
- Real-time updates
-
GraphQL Query Components:
- Fields (specific data)
- Types (data types)
- Resolvers (functions retrieving data)
- Queries (fetching data)
- Mutations (modifying data)
- Subscriptions (real-time updates)
| GraphQL | REST | |
|---|---|---|
| Query structure | Declarative | Imperative |
| Data retrieval | Specific fields | Entire resource |
| API endpoints | Single endpoint | Multiple endpoints |
| Data types | Strongly typed | Weakly typed |
| Real-time updates | Native support | WebSockets or polling |
| Performance | Fast | Multiple network calls take up more time |
| Web caching | Uses web library | Inbuilt |
| File uploading | No | Yes |