Skip to content

Commit e3188f1

Browse files
fix: GraphQL vs REST blog post minor textual improvements
1 parent cb69cd3 commit e3188f1

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

data/blog/software-development/web-services/graphql-vs-rest.mdx

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,7 @@ REST is built on six fundamental principles:
3434
5. **Layered System**: Architecture can be layered for scalability
3535
6. **Code on Demand**: Optional execution of code on the client
3636

37-
### Core REST Principles
38-
39-
REST is built on six fundamental principles:
40-
41-
1. **Client-Server Architecture**: Separation of concerns between client and server
42-
2. **Stateless**: Each request contains all necessary information
43-
3. **Cacheable**: Responses can be cached at various levels
44-
4. **Uniform Interface**: Consistent patterns across all endpoints
45-
5. **Layered System**: Architecture can be layered for scalability
46-
6. **Code on Demand**: Optional execution of code on the client
47-
48-
### Key Characteristics of REST:
37+
### Key Characteristics of REST
4938

5039
- **Resource-based**: Each endpoint represents a specific resource (e.g., `/users`, `/posts`)
5140
- **HTTP methods**: Uses standard HTTP verbs (GET, POST, PUT, DELETE, PATCH)
@@ -54,7 +43,7 @@ REST is built on six fundamental principles:
5443
- **Uniform interface**: Consistent patterns across all endpoints
5544
- **HATEOAS**: Hypermedia as the Engine of Application State (optional)
5645

57-
### REST API Example with Full CRUD Operations:
46+
### REST API Example with Full CRUD Operations
5847

5948
```javascript
6049
// Get all users with pagination
@@ -115,7 +104,7 @@ Content-Type: application/json
115104
}
116105
```
117106

118-
### HTTP Status Codes in REST:
107+
### HTTP Status Codes in REST
119108

120109
```javascript
121110
// Success Responses
@@ -137,18 +126,18 @@ Content-Type: application/json
137126
503 Service Unavailable - Service temporarily unavailable
138127
```
139128

140-
### Advantages of REST:
129+
### Advantages of REST
141130

142131
1. **Simplicity**: Easy to understand and implement
143132
2. **Wide adoption**: Extensive tooling and community support
144133
3. **Caching**: Built-in HTTP caching mechanisms
145134
4. **Stateless**: Scales horizontally without session management
146135
5. **Standards**: Follows HTTP conventions
147136
6. **Browser support**: Native browser support for HTTP methods
148-
7. **CDN friendly**: Easy to cache and distribute globally
137+
7. **CDN-friendly**: Easy to cache and distribute globally
149138
8. **Monitoring**: Standard HTTP monitoring tools work out of the box
150139

151-
### Limitations of REST:
140+
### Limitations of REST
152141

153142
1. **Over-fetching**: Often returns more data than needed
154143
2. **Under-fetching**: May require multiple requests for related data
@@ -172,7 +161,7 @@ GraphQL is built on several key concepts:
172161
4. **Type System**: Strong typing for all data structures
173162
5. **Introspection**: Self-documenting API capabilities
174163

175-
### Key Characteristics of GraphQL:
164+
### Key Characteristics of GraphQL
176165

177166
- **Query language**: Clients specify exactly what data they want
178167
- **Single endpoint**: All requests go through one endpoint (usually `/graphql`)
@@ -183,7 +172,7 @@ GraphQL is built on several key concepts:
183172
- **Aliases**: Multiple queries in a single request
184173
- **Fragments**: Reusable query parts
185174

186-
### GraphQL Schema Example:
175+
### GraphQL Schema Example
187176

188177
```graphql
189178
# Schema Definition
@@ -258,7 +247,7 @@ input ProfileInput {
258247
scalar DateTime
259248
```
260249

261-
### GraphQL Query Examples:
250+
### GraphQL Query Examples
262251

263252
```graphql
264253
# Basic Query
@@ -339,7 +328,7 @@ query SearchUsers($query: String!, $limit: Int = 10, $offset: Int = 0) {
339328
}
340329
```
341330

342-
### GraphQL Mutation Examples:
331+
### GraphQL Mutation Examples
343332

344333
```graphql
345334
# Create User Mutation
@@ -380,7 +369,7 @@ mutation BatchCreateUsers($inputs: [CreateUserInput!]!) {
380369
}
381370
```
382371

383-
### GraphQL Subscription Example:
372+
### GraphQL Subscription Example
384373

385374
```graphql
386375
# Real-time User Updates
@@ -413,7 +402,7 @@ subscription NewPosts {
413402
}
414403
```
415404

416-
### Advantages of GraphQL:
405+
### Advantages of GraphQL
417406

418407
1. **Efficient data fetching**: Get exactly what you need in one request
419408
2. **Strong typing**: Compile-time error checking
@@ -426,7 +415,7 @@ subscription NewPosts {
426415
9. **Built-in documentation**: Schema introspection
427416
10. **Graph structure**: Natural representation of data relationships
428417

429-
### Limitations of GraphQL:
418+
### Limitations of GraphQL
430419

431420
1. **Complexity**: Steeper learning curve
432421
2. **Caching**: More complex than HTTP caching
@@ -441,7 +430,7 @@ subscription NewPosts {
441430

442431
### Data Fetching Patterns
443432

444-
#### REST Data Fetching:
433+
#### REST Data Fetching
445434

446435
```javascript
447436
// REST requires multiple requests for related data
@@ -464,7 +453,7 @@ const settings = await settingsResponse.json();
464453
// Total: 4 HTTP requests, potential over-fetching
465454
```
466455

467-
#### GraphQL Data Fetching:
456+
#### GraphQL Data Fetching
468457

469458
```graphql
470459
# Single request gets all needed data
@@ -495,7 +484,7 @@ query GetUserComplete($userId: ID!) {
495484

496485
### Error Handling Comparison
497486

498-
#### REST Error Handling:
487+
#### REST Error Handling
499488

500489
```javascript
501490
// REST uses HTTP status codes
@@ -518,7 +507,7 @@ try {
518507
}
519508
```
520509

521-
#### GraphQL Error Handling:
510+
#### GraphQL Error Handling
522511

523512
```graphql
524513
# GraphQL returns partial data with errors
@@ -559,7 +548,7 @@ query GetUserWithPosts($userId: ID!) {
559548

560549
### Caching Strategies
561550

562-
#### REST Caching:
551+
#### REST Caching
563552

564553
```javascript
565554
// REST has built-in HTTP caching
@@ -576,7 +565,7 @@ const response = await fetch('/api/users/123', {
576565
// Simple and effective
577566
```
578567

579-
#### GraphQL Caching:
568+
#### GraphQL Caching
580569

581570
```javascript
582571
// GraphQL requires custom caching strategies

0 commit comments

Comments
 (0)