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: 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.mdx
Remember: APIs are the backbone of modern web apps. Focus on proper async patterns and error handling-these skills transfer to every web project!