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 @@
Example API Response:
+[
+ {
+ "id": 1,
+ "name": "Alice Johnson",
+ "email": "alice@example.com"
+ },
+ {
+ "id": 2,
+ "name": "Bob Smith",
+ "email": "bob@example.com"
+ }
+]
+
+ 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.
Example Error Responses:
+// 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"
+ }
+}
+
+ 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 @@
Testing with curl:
+# 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
+
+ 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 @@Testing with curl:
+# 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
+
+ Track and manage API version compatibility on the client side: