diff --git a/src/content/day1.html b/src/content/day1.html index c3a631e..09d3432 100644 --- a/src/content/day1.html +++ b/src/content/day1.html @@ -313,6 +313,30 @@

2. Complete CRUD Endpoints

+

Example API Response:

+
+
+ JSON - GET /api/users Response + +
+
[
+  {
+    "id": 1,
+    "name": "Alice Johnson",
+    "email": "alice@example.com"
+  },
+  {
+    "id": 2,
+    "name": "Bob Smith",
+    "email": "bob@example.com"
+  }
+]
+
+
+

3. Building an Actual API with Node.js HTTP Module

Understanding Node.js core http module helps you appreciate what frameworks like Express abstract away. This example builds a complete server with routing, template rendering, and an API endpoint from scratch.

diff --git a/src/content/day3.html b/src/content/day3.html index 11fd92c..2069786 100644 --- a/src/content/day3.html +++ b/src/content/day3.html @@ -124,6 +124,40 @@

1. Consistent Error Response Format

+

Example Error Responses:

+
+
+ JSON - Error Response Examples + +
+
// 404 Not Found Response
+{
+  "error": {
+    "status": 404,
+    "message": "User not found",
+    "details": null,
+    "timestamp": "2025-12-26T10:30:00.000Z"
+  }
+}
+
+// 422 Validation Error Response
+{
+  "error": {
+    "status": 422,
+    "message": "Validation failed",
+    "details": {
+      "email": "Invalid email format",
+      "age": "Must be at least 18"
+    },
+    "timestamp": "2025-12-26T10:30:00.000Z"
+  }
+}
+
+
+

2. Centralized Error Handling Middleware

Problem solved: Catches all errors from routes in one place, ensuring consistent error responses and proper logging without duplicating code. diff --git a/src/content/day5.html b/src/content/day5.html index d0e265b..7c22885 100644 --- a/src/content/day5.html +++ b/src/content/day5.html @@ -275,14 +275,27 @@

2. Header-Based Versioning

app.use(checkDeprecation); app.listen(3000, () => console.log('Header-versioned API running')); - -// Example usage: -// curl -H "Accept-Version: 1.0" http://localhost:3000/api/users -// curl -H "Accept-Version: 2.0" http://localhost:3000/api/users +

Testing with curl:

+
+
+ Bash - Testing Header Versioning + +
+
# Test with version 1.0
+curl -H "Accept-Version: 1.0" http://localhost:3000/api/users
+
+# Test with version 2.0
+curl -H "Accept-Version: 2.0" http://localhost:3000/api/users
+
+
+

3. Content Negotiation Versioning

Use custom media types in the Accept header to specify API version. Follows REST principles by treating different versions as different resource representations.

@@ -385,14 +398,27 @@

3. Content Negotiation Versioning

}); app.listen(3000, () => console.log('Content negotiation API running')); - -// Example usage: -// curl -H "Accept: application/vnd.myapi.v1+json" http://localhost:3000/api/users -// curl -H "Accept: application/vnd.myapi.v2+json" http://localhost:3000/api/users +

Testing with curl:

+
+
+ Bash - Testing Content Negotiation + +
+
# Test with version 1 using custom media type
+curl -H "Accept: application/vnd.myapi.v1+json" http://localhost:3000/api/users
+
+# Test with version 2 using custom media type
+curl -H "Accept: application/vnd.myapi.v2+json" http://localhost:3000/api/users
+
+
+

💾 localStorage Practical: API Version Manager

Track and manage API version compatibility on the client side: