Skip to content

Commit efb9da8

Browse files
fix: GraphQL vs REST blog post minor improvements after reading
1 parent cc28802 commit efb9da8

File tree

1 file changed

+20
-38
lines changed

1 file changed

+20
-38
lines changed

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

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,17 @@ This comprehensive guide will help you understand the key differences between RE
2323

2424
REST API (Representational State Transfer) has been the dominant API architecture for over two decades, and for good reason. It's simple, stateless, and follows well-established HTTP conventions. REST APIs are the foundation of modern web services and are used by millions of applications worldwide.
2525

26-
### Core REST Principles
27-
28-
REST is built on six fundamental principles:
29-
30-
1. **Client-Server Architecture**: Separation of concerns between client and server
31-
2. **Stateless**: Each request contains all necessary information
32-
3. **Cacheable**: Responses can be cached at various levels
33-
4. **Uniform Interface**: Consistent patterns across all endpoints
34-
5. **Layered System**: Architecture can be layered for scalability
35-
6. **Code on Demand**: Optional execution of code on the client
36-
3726
### Key Characteristics of REST
3827

28+
REST is built on six fundamental principles and follows these key characteristics:
29+
3930
- **Resource-based**: Each endpoint represents a specific resource (e.g., `/users`, `/posts`)
4031
- **HTTP methods**: Uses standard HTTP verbs (GET, POST, PUT, DELETE, PATCH)
4132
- **Stateless**: Each request contains all necessary information
4233
- **Cacheable**: Responses can be cached at various levels
4334
- **Uniform interface**: Consistent patterns across all endpoints
35+
- **Client-Server Architecture**: Separation of concerns between client and server
36+
- **Layered System**: Architecture can be layered for scalability
4437
- **HATEOAS**: Hypermedia as the Engine of Application State (optional)
4538

4639
### REST API Example with Full CRUD Operations
@@ -151,23 +144,17 @@ Content-Type: application/json
151144

152145
GraphQL, developed by Facebook in 2015, offers a more flexible and efficient approach to data fetching. It allows clients to request exactly the data they need, nothing more and nothing less. GraphQL has revolutionized how developers think about API design and data retrieval.
153146

154-
### Core GraphQL Concepts
155-
156-
GraphQL is built on several key concepts:
157-
158-
1. **Schema Definition Language (SDL)**: Defines the API structure
159-
2. **Resolvers**: Functions that fetch data for each field
160-
3. **Query Language**: Client-specified data requirements
161-
4. **Type System**: Strong typing for all data structures
162-
5. **Introspection**: Self-documenting API capabilities
163-
164147
### Key Characteristics of GraphQL
165148

149+
GraphQL is built on several key concepts and offers these characteristics:
150+
166151
- **Query language**: Clients specify exactly what data they want
167152
- **Single endpoint**: All requests go through one endpoint (usually `/graphql`)
168-
- **Strong typing**: Schema defines available data and operations
153+
- **Strong typing**: Schema defines available data and operations with compile-time checking
154+
- **Schema Definition Language (SDL)**: Defines the API structure
155+
- **Resolvers**: Functions that fetch data for each field
169156
- **Real-time updates**: Built-in subscription support
170-
- **Introspection**: Self-documenting API
157+
- **Introspection**: Self-documenting API capabilities
171158
- **Field-level resolution**: Each field can have its own resolver
172159
- **Aliases**: Multiple queries in a single request
173160
- **Fragments**: Reusable query parts
@@ -216,7 +203,6 @@ type Mutation {
216203
createUser(input: CreateUserInput!): User!
217204
updateUser(id: ID!, input: UpdateUserInput!): User!
218205
deleteUser(id: ID!): Boolean!
219-
createPost(input: CreatePostInput!): Post!
220206
}
221207

222208
type Subscription {
@@ -332,7 +318,7 @@ query SearchUsers($query: String!, $limit: Int = 10, $offset: Int = 0) {
332318

333319
```graphql
334320
# Create User Mutation
335-
mutation CreateUser($input: CreateUserInput!) {
321+
mutation createUser($input: CreateUserInput!) {
336322
createUser(input: $input) {
337323
id
338324
name
@@ -346,7 +332,7 @@ mutation CreateUser($input: CreateUserInput!) {
346332
}
347333

348334
# Update User Mutation
349-
mutation UpdateUser($id: ID!, $input: UpdateUserInput!) {
335+
mutation updateUser($id: ID!, $input: UpdateUserInput!) {
350336
updateUser(id: $id, input: $input) {
351337
id
352338
name
@@ -359,13 +345,9 @@ mutation UpdateUser($id: ID!, $input: UpdateUserInput!) {
359345
}
360346
}
361347

362-
# Batch Operations
363-
mutation BatchCreateUsers($inputs: [CreateUserInput!]!) {
364-
batchCreateUsers(inputs: $inputs) {
365-
id
366-
name
367-
email
368-
}
348+
# Delete User Mutation
349+
mutation deleteUser($id: ID!) {
350+
deleteUser(id: $id)
369351
}
370352
```
371353

@@ -462,17 +444,17 @@ query GetUserComplete($userId: ID!) {
462444
id
463445
name
464446
email
465-
profile {
466-
bio
467-
location
468-
avatar
469-
}
470447
posts {
471448
id
472449
title
473450
content
474451
createdAt
475452
}
453+
profile {
454+
bio
455+
location
456+
avatar
457+
}
476458
settings {
477459
theme
478460
notifications

0 commit comments

Comments
 (0)