Using the Steam API with Next.js to show current playing game on your website
Ali Heydari
⏳ 2 min read
Introduction
I set up a Spotify now listening widget on my website and I thought it would be cool to have a similar widget for Steam.
I searched for a while and I found a Steam API
that can be used to get the current playing game. In this article,
I will show you how to show your current playing game from Steam on your website using NextJS and Steam API.
Create NextJS project
First, we need to create a NextJS project. You can create it by running the following command.
Get Steam API Key
Now, you need to get a Steam API key. You can get it from here.
NOTE: If you haven't bought any game from Steam, you can't get a Steam API key.
Inside your NextJS project, create a file called .env.local and add STEAM_API_KEY and STEAM_ID
from the previous steps to it.
Then, create a file called lib/steam.ts and add the following code to it.
Create an API route
Now, we need to create an API route to get the current playing game.
Create a file called app/api/steam/now-playing.ts and add the following code to it.
I'm using NextJS app router to create API routes.
Test the API route
Now, you can test the API route by running the following command.