Complete solution (100% reference)
index.html- Main HTML pagescript.js- JavaScript logicstyles.css- Styling and layoutpackage.json- Dependenciessetup.sh- Setup scriptREADME.md- Instructions (below)๐ก Download the ZIP, extract it, and follow the instructions below to get started!
W3 Server-Side Development & Authentication - Lesson 13
Build a Steam game search application using SvelteKit and external API integration. This project introduces you to full-stack routing, API calls with fetch(), and managing asynchronous data in a modern web framework.
By completing this project, you will:
fetch()This template is from:
academic-telebort/Web-3-Project-4-Steam-Game-Searcherโ
SvelteKit project structure
โ
Basic routing configuration
โ
Empty components in src/lib/
โ
Minimal route files in src/routes/
โ
Development environment setup
Search Interface
Game Results Display
Game Details Page
API Integration
Navigate to this template folder:
cd "Paid Courses/W3 Server-Side Development & Authentication/Templates/project-04-game-searcher"
Install dependencies:
npm install
Start development server:
npm run dev
Open in browser:
Visit http://localhost:5173
project-04-game-searcher/
โโโ src/
โ โโโ lib/
โ โ โโโ GameCard.svelte # TODO: Create game card component
โ โ โโโ SearchBar.svelte # TODO: Create search component
โ โโโ routes/
โ โ โโโ +page.svelte # Home/search page (TODO: implement)
โ โ โโโ game/
โ โ โโโ [id]/
โ โ โโโ +page.svelte # Game details page (TODO: implement)
โ โโโ app.html # HTML shell
โโโ package.json
โโโ svelte.config.js
Before implementing, research and answer:
SvelteKit Routing: How does file-based routing work in SvelteKit?
[id])?API Integration: How do you fetch data from external APIs?
fetch() API?Steam API: What endpoints are available?
Error Handling: How do you handle API failures?
<!-- src/lib/SearchBar.svelte -->
<script>
// TODO: Import necessary functions
import { goto } from '$app/navigation';
// TODO: Create reactive variables
let searchQuery = '';
let loading = false;
// TODO: Implement search function
async function handleSearch() {
if (!searchQuery.trim()) return;
loading = true;
try {
// TODO: Call Steam API
const response = await fetch(`API_URL?search=${searchQuery}`);
const data = await response.json();
// TODO: Handle response
// Update UI with results
} catch (error) {
console.error('Search failed:', error);
// TODO: Show error message
} finally {
loading = false;
}
}
</script>
<!-- TODO: Create search UI -->
<form on:submit|preventDefault={handleSearch}>
<input bind:value={searchQuery} placeholder="Search games..." />
<button type="submit" disabled={loading}>
{loading ? 'Searching...' : 'Search'}
</button>
</form>
<!-- src/routes/+page.svelte -->
<script>
import GameCard from '$lib/GameCard.svelte';
import SearchBar from '$lib/SearchBar.svelte';
// TODO: Store search results
let games = [];
// TODO: Pass results to GameCard components
</script>
<SearchBar on:search={(e) => games = e.detail} />
<!-- TODO: Display results -->
{#if games.length > 0}
<div class="game-grid">
{#each games as game}
<GameCard {game} />
{/each}
</div>
{:else}
<p>No games found. Try searching!</p>
{/if}
<!-- src/routes/game/[id]/+page.svelte -->
<script>
import { page } from '$app/stores';
// TODO: Access route parameter
$: gameId = $page.params.id;
// TODO: Fetch game details
async function loadGameDetails() {
const response = await fetch(`API_URL/${gameId}`);
return await response.json();
}
// TODO: Load data when component mounts
</script>
<!-- TODO: Display game details -->
// RAWG API example
const searchGames = async (query) => {
const response = await fetch(
`https://api.rawg.io/api/games?search=${query}&key=YOUR_API_KEY`
);
const data = await response.json();
return data.results;
};
Your project is complete when:
Test these scenarios:
| Criteria | Points | Description |
|---|---|---|
| API Integration | 35 | Successful API calls, data parsing |
| Routing | 25 | Proper SvelteKit routing, navigation |
| Functionality | 25 | Search, display results, details page |
| Error Handling | 10 | Loading states, error messages |
| Code Quality | 5 | Clean code, async patterns |
| Total | 100 |
Issue: CORS errors when calling API Solution: Use a CORS-enabled API (like RAWG) or set up a proxy
Issue: Route parameters not accessible
Solution: Use $page.params from $app/stores
Issue: Images not loading Solution: Check image URLs from API response, some may be missing
Issue: Async data not rendering
Solution: Ensure you're using reactive statements ($:) or proper state updates
When ready to deploy:
npm run build
npm run preview # Preview production build
../../Project/Project 04- Steam Game Searcher.mdxRemember: APIs are the backbone of modern web apps. Focus on proper async patterns and error handling-these skills transfer to every web project!