Skip to content

Commit 44f0992

Browse files
authored
Merge pull request #4 from d2kole/claude/add-json-bash-support-LFNWq
Add JSON and Bash language support
2 parents bc94d4a + 2a36273 commit 44f0992

File tree

3 files changed

+92
-8
lines changed

3 files changed

+92
-8
lines changed

src/content/day1.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,30 @@ <h4>2. Complete CRUD Endpoints</h4>
313313
</div>
314314
</details>
315315

316+
<p><strong>Example API Response:</strong></p>
317+
<div class="code-block">
318+
<div class="code-header">
319+
<span>JSON - GET /api/users Response</span>
320+
<button class="copy-btn" onclick="copyCode(this, 'code-d1-2-response')">Copy</button>
321+
</div>
322+
<pre><code id="code-d1-2-response"
323+
class="language-json"
324+
data-type="response"
325+
data-description="Example JSON response from GET /api/users endpoint">[
326+
{
327+
"id": 1,
328+
"name": "Alice Johnson",
329+
"email": "[email protected]"
330+
},
331+
{
332+
"id": 2,
333+
"name": "Bob Smith",
334+
"email": "[email protected]"
335+
}
336+
]
337+
</code></pre>
338+
</div>
339+
316340
<h4>3. Building an Actual API with Node.js HTTP Module</h4>
317341
<p>Understanding Node.js core <code>http</code> 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.</p>
318342

src/content/day3.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,40 @@ <h4>1. Consistent Error Response Format</h4>
124124
</div>
125125
</details>
126126

127+
<p><strong>Example Error Responses:</strong></p>
128+
<div class="code-block">
129+
<div class="code-header">
130+
<span>JSON - Error Response Examples</span>
131+
<button class="copy-btn" onclick="copyCode(this, 'code-d3-1-error-json')">Copy</button>
132+
</div>
133+
<pre><code id="code-d3-1-error-json"
134+
class="language-json"
135+
data-type="error-response"
136+
data-description="Example JSON error responses with consistent structure">// 404 Not Found Response
137+
{
138+
"error": {
139+
"status": 404,
140+
"message": "User not found",
141+
"details": null,
142+
"timestamp": "2025-12-26T10:30:00.000Z"
143+
}
144+
}
145+
146+
// 422 Validation Error Response
147+
{
148+
"error": {
149+
"status": 422,
150+
"message": "Validation failed",
151+
"details": {
152+
"email": "Invalid email format",
153+
"age": "Must be at least 18"
154+
},
155+
"timestamp": "2025-12-26T10:30:00.000Z"
156+
}
157+
}
158+
</code></pre>
159+
</div>
160+
127161
<h4>2. Centralized Error Handling Middleware</h4>
128162
<p class="code-description">
129163
<strong>Problem solved:</strong> Catches all errors from routes in one place, ensuring consistent error responses and proper logging without duplicating code.

src/content/day5.html

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,27 @@ <h4>2. Header-Based Versioning</h4>
275275
app.use(checkDeprecation);
276276

277277
app.listen(3000, () => console.log('Header-versioned API running'));
278-
279-
// Example usage:
280-
// curl -H "Accept-Version: 1.0" http://localhost:3000/api/users
281-
// curl -H "Accept-Version: 2.0" http://localhost:3000/api/users
282278
</code></pre>
283279
</div>
284280
</details>
285281

282+
<p><strong>Testing with curl:</strong></p>
283+
<div class="code-block">
284+
<div class="code-header">
285+
<span>Bash - Testing Header Versioning</span>
286+
<button class="copy-btn" onclick="copyCode(this, 'code-d5-2-curl')">Copy</button>
287+
</div>
288+
<pre><code id="code-d5-2-curl"
289+
class="language-bash"
290+
data-type="testing"
291+
data-description="curl commands to test header-based API versioning"># Test with version 1.0
292+
curl -H "Accept-Version: 1.0" http://localhost:3000/api/users
293+
294+
# Test with version 2.0
295+
curl -H "Accept-Version: 2.0" http://localhost:3000/api/users
296+
</code></pre>
297+
</div>
298+
286299
<h4>3. Content Negotiation Versioning</h4>
287300
<p>Use custom media types in the Accept header to specify API version. Follows REST principles by treating different versions as different resource representations.</p>
288301

@@ -385,14 +398,27 @@ <h4>3. Content Negotiation Versioning</h4>
385398
});
386399

387400
app.listen(3000, () => console.log('Content negotiation API running'));
388-
389-
// Example usage:
390-
// curl -H "Accept: application/vnd.myapi.v1+json" http://localhost:3000/api/users
391-
// curl -H "Accept: application/vnd.myapi.v2+json" http://localhost:3000/api/users
392401
</code></pre>
393402
</div>
394403
</details>
395404

405+
<p><strong>Testing with curl:</strong></p>
406+
<div class="code-block">
407+
<div class="code-header">
408+
<span>Bash - Testing Content Negotiation</span>
409+
<button class="copy-btn" onclick="copyCode(this, 'code-d5-3-curl')">Copy</button>
410+
</div>
411+
<pre><code id="code-d5-3-curl"
412+
class="language-bash"
413+
data-type="testing"
414+
data-description="curl commands to test content negotiation versioning"># Test with version 1 using custom media type
415+
curl -H "Accept: application/vnd.myapi.v1+json" http://localhost:3000/api/users
416+
417+
# Test with version 2 using custom media type
418+
curl -H "Accept: application/vnd.myapi.v2+json" http://localhost:3000/api/users
419+
</code></pre>
420+
</div>
421+
396422
<div class="storage-demo">
397423
<h4>💾 localStorage Practical: API Version Manager</h4>
398424
<p>Track and manage API version compatibility on the client side:</p>

0 commit comments

Comments
 (0)