🚀 API Explorer

Learn to work with APIs using Fetch API

🌐 Your API Base URL: https://api.techshare.cc/api

🎮 Basic Tasks

📋 Task 1: Get All Users

fetch('https://api.techshare.cc/api/users') .then(response => response.json()) .then(data => { document.getElementById('users').textContent = JSON.stringify(data); })
JSON.stringify(data) converts JavaScript objects to readable text.
Results will appear here...

👤 Task 2: Get a Specific User

fetch('https://api.techshare.cc/api/users/693c0a4357cce1118095f635') .then(response => response.json()) .then(data => { document.getElementById('user').textContent = JSON.stringify(data); })
Results will appear here...

📝 Task 3: Get All Posts

fetch('https://api.techshare.cc/api/posts') .then(response => response.json()) .then(data => { const titles = data.map(post => post.title); document.getElementById('posts').textContent = JSON.stringify(titles); })
.map() extracts just the title from each post.
Results will appear here...

➕ Task 4: Create a New Post

const title = document.getElementById('postTitle').value; const content = document.getElementById('postContent').value; const published = document.getElementById('postPublished').checked; fetch('https://api.techshare.cc/api/posts', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ title: title, content: content, userId: '693c0a4357cce1118095f635', published: published }) }) .then(response => response.json()) .then(data => { document.getElementById('create').textContent = JSON.stringify(data); })
method: 'POST' creates new data.
userId is hardcoded to user 693c0a4357cce1118095f635.
Results will appear here...

💡 Bonus Challenges

🔍 Challenge 1: Filter Posts by User ID

First, run Task 2 to see user details. Note the id field (not _id).

const userId = document.getElementById('userIdInput').value; fetch('https://api.techshare.cc/api/posts') .then(response => response.json()) .then(posts => { const userPosts = posts.filter(post => post.userId === Number(userId)); document.getElementById('filter').textContent = 'Posts by user ID ' + userId + ': ' + JSON.stringify(userPosts); })
Number(userId) converts text to number for comparison.
Posts use userId (like 1, 2, 3), not MongoDB _id.
Results will appear here...
💡 Important: User ID in posts is different from MongoDB _id. Check Task 2 results: user 693c0a4357cce1118095f635 has id: "1". So posts with userId: 1 belong to this user.