This commit is contained in:
2025-12-15 15:39:31 +03:00
parent 0886fb902b
commit cbbee493d0
2 changed files with 95 additions and 0 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@@ -0,0 +1,95 @@
<!DOCTYPE html>
<!-- saved from url=(0063)file:///Users/home/Downloads/deepseek_html_20251215_dacfff.html -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API Exercises Starter Template</title>
</head>
<body>
<h1>API Exercises</h1>
<h2>Task 1: GET All Users (READ)</h2>
<button onclick="
fetch(&#39;https://api.techshare.cc/api/users&#39;)
.then(response =&gt; response.json())
.then(data =&gt; {
console.log(&#39;First 3 users:&#39;, data.slice(0, 3));
alert(&#39;Check console for first 3 users!&#39;);
})
.catch(error =&gt; console.error(&#39;Error:&#39;, error));
">
Get Users
</button>
<h2>Task 2: GET Single User (READ)</h2>
<button onclick="
fetch(&#39;https://api.techshare.cc/api/users/693c0a4357cce1118095f635&#39;)
.then(response =&gt; response.json())
.then(data =&gt; {
console.log(&#39;Single user:&#39;, data);
alert(&#39;Check console for single user data!&#39;);
})
.catch(error =&gt; console.error(&#39;Error:&#39;, error));
">
Get User by _id
</button>
<h2>Task 3: GET All Posts (READ)</h2>
<button onclick="
fetch(&#39;https://api.techshare.cc/api/posts&#39;)
.then(response =&gt; response.json())
.then(data =&gt; {
const titles = data.map(post =&gt; post.title);
console.log(&#39;First 5 titles:&#39;, titles.slice(0, 5));
alert(&#39;Check console for first 5 post titles!&#39;);
})
.catch(error =&gt; console.error(&#39;Error:&#39;, error));
">
Get Posts (Titles Only)
</button>
<h2>Task 4: CREATE a Post (CREATE)</h2>
<button onclick="
fetch(&#39;https://api.techshare.cc/api/posts&#39;, {
method: &#39;POST&#39;,
headers: {
&#39;Content-Type&#39;: &#39;application/json&#39;
},
body: JSON.stringify({
title: &#39;My First API Post&#39;,
content: &#39;Learning APIs is fun!&#39;,
userId: 1,
published: true
})
})
.then(response =&gt; response.json())
.then(data =&gt; {
console.log(&#39;New post created:&#39;, data);
alert(&#39;Post created! Check console for details.&#39;);
})
.catch(error =&gt; console.error(&#39;Error:&#39;, error));
">
Create Post
</button>
<h2>Bonus: Filter Posts by User (READ)</h2>
<button onclick="
fetch(&#39;https://api.techshare.cc/api/posts&#39;)
.then(response =&gt; response.json())
.then(posts =&gt; {
const userPosts = posts.filter(post =&gt; post.userId === 1);
console.log(&#39;Posts by user 1:&#39;, userPosts);
alert(&#39;Check console for posts by user 1!&#39;);
})
.catch(error =&gt; console.error(&#39;Error:&#39;, error));
">
Filter Posts by User
</button>
<script>
// Optional: You could move the functions here for cleaner separation
// But keeping them in onclick handlers as requested
console.log('API Exercises Template Ready!');
</script>
</body></html>