Video games have come a long way in recent years due to the advent of mobile devices, gaming consoles, social media networks, and advances in computer technology. Today’s games have taken the gaming industry to a whole new level with exciting gameplays, engaging plots, realistic graphics/simulations, and thrilling challenges. The huge popularity of video games has led to the need for comprehensive and up-to-date video-games information. This has in turn led to the emergence of several REST APIs for video games. One such API is the RAWG Video Games Database API. In this article, we will be learning about this API and its features.
What is the RAWG Video Games Database API?
RAWG is a video games database and a game discovery service. It is one of the largest video games databases and includes information about more than 350,000 games for 50 different gaming platforms. Users can use the RAWG web application to browse for games by release date, popularity, platform (PC, Playstation, Xbox), Genre (action, puzzle, sports) storefronts (PlayStation, App store, Google play), and much more! Users can also create collections/wishlists of their favorite games and rate/recommend games. Moreover, RAWG connects users to storefronts from where they can directly purchase the game. The RAWG Video Games Database API is a REST API for the RAWG application. So, it provides endpoints that expose some of the RAWG database data.
Who is the target audience for the RAWG Video Games Database API?
There are a large number of gaming communities/forums available on the internet where users can chat and discuss games. Such applications can utilize the RAWG Video Games Database API to obtain the latest gaming information which can then be made available to users for discussions.
Due to the huge popularity of video games, game fans are constantly looking for the latest video game information. Thus, the RAWG Video Games Database API can be used to create video games related websites/mobile applications to provide such information to gaming enthusiasts worldwide. Moreover, such applications can even leverage the API endpoints to incorporate search features (searching for games by genre, platform, storefront) into their application if desired.
Finally, the RAWG Video Games Database API can be used by mobile game developers/publishers to obtain information about the currently available games, genres, platforms, etc. as well as information about competitors. Knowing what is available can help game developers improve their strategy for producing new games.
How does the RAWG Video Games Database API work?
The RAWG Video Games Database API is a REST API. In simple terms, a REST API exposes information in the form of HTTP URLs which are also known as REST endpoints. An application that wishes to obtain information from the REST API (also known as a REST client or client application), needs to query the particular REST endpoint. While querying, it needs to supply the endpoint URL, request parameters (any information required by the endpoint), and authentication information (an API key). The REST endpoint then processes the request. It returns an HTTP status code indicating whether the request was successful or not. It may also optionally return data corresponding to the request. The RAWG Video Games Database API works on the same principles. It exposes several endpoints that return information about all the games, genres, platforms, etc. A client application can query these endpoints to obtain the required information.
How to use the RAWG Video Games Database API
You can use RapidAPI to connect to the RAWG Video Games Database API. Not only does RapidAPI list all the API endpoints, but it also provides code snippets in popular programming languages which can be used to execute the API endpoints.
In order to use RapidAPI to connect to the RAWG Video Games Database API, you need to follow the steps given below.
Step 1 – Signing Up to Rapid API
The first step is to create a RapidAPI account as described below.
Step 1a – Enter the RAWG Video Games Database RapidAPI URL (https://rapidapi.com/accujazz/api/rawg-video-games-database ) in a browser. Click on the Log In/Sign Up button in the top right corner. This redirects to the following authentication page:
Step 1b – Authenticate yourself using any of the methods shown on the page like Google, GitHub, Facebook, etc. Upon successful authentication, the following page is displayed:
Step 2 – Obtaining RAWG Key
The RAWG Video games database API requires an additional key to be supplied while executing an endpoint. This key can be obtained from the RAWG website as follows:
Step 2a – Visit https://rawg.io/apidocs. Click on the Get API Key button:
Step 2b – On the authentication page displayed, authenticate yourself using any of the methods shown like Email, Facebook, Twitter, etc.:
Step 2c – Upon successful authentication, click on the API link at the top right on the displayed page:
Step 2d – Save the API key displayed on the resulting page for future use:
Step 3 – Obtaining a code snippet
As mentioned above, RapidAPI provides code snippets for executing all the API endpoints in most of the popular programming languages. A code snippet can be obtained as follows:
Step 3a – Click on the EndPoints tab. All the available endpoints are displayed on the left:
Step 3b – Click on the desired endpoint from the endpoints list on the left. I have selected the Get a list of games endpoint. Click on the Code snippets tab on the right. Select the desired programming language and HTTP client in the language selection drop-down. I have selected Java -> OkHttp:
Step 3c – Copy the displayed code and use it as desired:
Step 4 – Executing an endpoint
RapidAPI allows executing API endpoints directly in the browser. However, in the case of the RAWG Video Games Database API, the key obtained from RAWG needs to be appended to an endpoint URL in order to execute it. Hence, unlike other APIs available on RapidAPI, the RAWG Video Games Database API endpoints cannot be directly executed by clicking the Test Endpoint button and will give an incorrect response as shown below:
The RAWG Video Games Database API endpoints can be executed via code. In order to execute an API endpoint, you need to copy the code obtained from RapidAPI as explained above and append the key to the endpoint URL as follows:
https://<RAWG_URL>?key=<Key from RAWG>
(Replace <RAWG_URL>
with the endpoint URL and <Key from RAWG>
with the key obtained from RAWG.)
The code below demonstrates the complete Java code after appending the RAWG key to the Get a list of games endpoint URL:
OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("https://rawg-video-games-database.p.rapidapi.com/games?key=<key from RAWG>") .get() .addHeader("x-rapidapi-key", "<rapid api key>") .addHeader("x-rapidapi-host", "rawg-video-games-database.p.rapidapi.com") .build(); Response response = client.newCall(request).execute();
This code can then be executed in order to obtain the endpoint response.
RAWG Video Games Database API Endpoints
Let us now take a detailed look at the RAWG Video Games Database API endpoints. The following table describes all the API endpoints.
Category | Endpoint Name | Endpoint Description | Parameters |
Games | Get a list of games | Returns a list of all the available games. For each game, returns information like game name, game release date, game rating, etc. | None |
Games | Get game details | Returns information about a particular game like its name, description, reviews, platforms on which it runs, etc. | game_pk – Required parameter of type String. Corresponds to the id of the game whose details are required |
Genres | Get a list of video games genres | Returns a list of all the available video game genres. (like action, strategy, puzzle, etc.) For each genre, returns information like the genre name, number of games belonging to that genre, list of games belonging to that genre, etc. | None |
Genres | Get genres details | Returns details of a particular video game genre like its name, description, etc. | id – Required parameter of type number. Corresponds to the id of the genre whose details are required |
Platforms | Get a list of video games platform | Returns a list of all the available video game platforms (like PC, PlayStation 4, Xbox One, etc.). For each platform, returns information like the name of the platform, number of games running on that platform, list of games running on that platform, etc. | None |
Platforms | Get platform details | Returns details of a particular platform like its name, description, etc. | id – Required parameter of type number. Corresponds to the id of the platform whose details are required |
Publishers | Get a list of video game publisher | Returns a list of all the available video game publishers (like Electronic Arts, Square Enix, etc.). For each publisher, returns information like the publisher name, number of games published by the publisher, list of games published by the publisher, etc. | None |
Publishers | Get publisher details | Returns details of a particular publisher like its name, description, etc. | id – Required parameter of type number. Corresponds to the id of the publisher whose details are required |
Stores | Get a list of video game storefronts | Returns a list of all the available video game storefronts (like PlayStation Store, Google Play Store, App Store, etc.). For each store, returns information like the store name, number of games available in the store, list of games available in the store, etc. | None |
Stores | Get store details | Returns details of a particular store like its name, description, etc. | id – Required parameter of type number. Corresponds to the id of the store whose details are required |
Tags | Get a list of tags | Returns a list of all the available video game tags (like Singleplayer, Multiplayer, 2D, etc.). For each tag, returns information about the tag name, number of games with that tag, list of games with that tag, etc. | None |
Tags | Get tag details | Returns details of a particular tag like its name, description, etc. | id – Required parameter of type number. Corresponds to the id of the tag whose details are required |
Developers | Get a list of game developers | Returns a list of all the available game developers (like Ubisoft, Capcom, SEGA, etc.). For each developer, returns information like the developer name, number of games created by that developer, list of all the games created by the developer, etc. | None |
Developers | Get developer details | Returns details of a particular developer like name, description, etc. | id – Required parameter of type number. Corresponds to the id of the developer whose details are required |
Creators | Get a list of game creators | Returns a list of all the available game creators (like Todd Howard, Jason Graves, etc.). For each creator, returns information like the creator name, number of games created by the creator, list of games created by the creator, etc. | None |
Creators | Get create details | Returns details of a particular game creator like his/her name, description, reviews, etc. | id – Required parameter of type number. Corresponds to the id of the game creator whose details are required |
Creator Roles | Get a list of creator position(jobs) | Returns a list of all the creator positions (like writer, composer, director, etc.) | None |
How to use the RAWG Video Database API with various programming languages
Since the RAWG Video Database API is a REST API, it can be invoked by a REST client in any programming language. As explained earlier, a REST API exposes its endpoints as HTTP URLs. Thus, a programming language specific HTTP client library needs to be used to invoke an API endpoint. Most programming languages support multiple HTTP libraries. Not only does RapidAPI provides code snippets in various programming languages, but it provides code for multiple HTTP libraries in each programming language. These can be used to invoke the API endpoints. Also, in order to execute an endpoint, the key obtained from RAWG needs to appended to the endpoint URL as explained earlier.
Let us now take a look at a few code samples in various programming languages. All the examples shown below invoke the Get a list of games endpoint.
Using the RAWG Video Database API with Java
There are several HTTP client libraries available for Java like OkHttp, Unirest, AsyncHttp, and java.net.http. The following code demonstrates how you can invoke an API endpoint using the OKHTTP library:
OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("https://rawg-video-games-database.p.rapidapi.com/games?key=<key from RAWG>") .get() .addHeader("x-rapidapi-key", "e6ef05302emsh9c46dd59d7ac5d1p13a2d8jsneb37aae7d452") .addHeader("x-rapidapi-host", "rawg-video-games-database.p.rapidapi.com") .build(); Response response = client.newCall(request).execute();
Using the RAWG Video Database API with Python
Like Java, there are several HTTP client libraries available for Python like http.client, Requests, and Unirest. The following code demonstrates how you can invoke an API endpoint using the Requests library:
import requests url = "https://rawg-video-games-database.p.rapidapi.com/games?key=<key from RAWG>" headers = { 'x-rapidapi-key': "e6ef05302emsh9c46dd59d7ac5d1p13a2d8jsneb37aae7d452", 'x-rapidapi-host': "rawg-video-games-database.p.rapidapi.com" } response = requests.request("GET", url, headers=headers) print(response.text)
Using the RAWG Video Database API with PHP
PHP also has many HTTP client libraries like cURL, HTTP v1, HTTP v2, and Unirest. The code below demonstrates invoking an API endpoint using the cURL library:
<?php $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://rawg-video-games-database.p.rapidapi.com/games?key=<key from RAWG>", CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => [ "x-rapidapi-host: rawg-video-games-database.p.rapidapi.com", "x-rapidapi-key: e6ef05302emsh9c46dd59d7ac5d1p13a2d8jsneb37aae7d452" ], ]); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }
Using the RAWG Video Database API with Ruby
Ruby has two main HTTP client libraries. These are net::http and Unirest. The following code demonstrates how an API endpoint can be invoked using the net::http client:
require 'uri' require 'net/http' require 'openssl' url = URI("https://rawg-video-games-database.p.rapidapi.com/games?key=<key from RAWG>") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-key"] = 'e6ef05302emsh9c46dd59d7ac5d1p13a2d8jsneb37aae7d452' request["x-rapidapi-host"] = 'rawg-video-games-database.p.rapidapi.com' response = http.request(request) puts response.read_body
Using the RAWG Video Database API with Javascript
Like other programming languages, Javascript too has many HTTP client libraries like jQuery, fetch, XMLHttpRequest, and Axios. The code below demonstrates invoking an API endpoint using the jQuery library:
const settings = { "async": true, "crossDomain": true, "url": "https://rawg-video-games-database.p.rapidapi.com/games?key=<key from RAWG>", "method": "GET", "headers": { "x-rapidapi-key": "e6ef05302emsh9c46dd59d7ac5d1p13a2d8jsneb37aae7d452", "x-rapidapi-host": "rawg-video-games-database.p.rapidapi.com" } }; $.ajax(settings).done(function (response) { console.log(response); });
Additionally, RapidAPI provides code snippets in several other programming languages like Node.js, C, Kotlin, Swift, etc. which can also be used to execute the API endpoints.
What are the benefits of the RAWG Video Games Database API?
Simple – The most important benefit of the RAWG Video Games API is that it is simple and easy to use. Though there are a lot of API endpoints, all of them are straightforward and self-explanatory. This reduces the developer ramp-up time and thereby increases the overall productivity.
Free – Another important benefit of the RAWG Video Games API is that it is completely free for personal and developer use. It is also free for commercial use for start-ups and small projects. This makes it a good option for developers/small organizations looking for a cost-effective and viable video games API.
Comprehensive Data – Finally, the RAWG video games database has data about thousands of games across several genres, platforms, and storefronts. This makes the API an excellent choice for anyone looking for wide-ranging game information.
Other APIs in the gaming arena
Let us now take a look at some other video game APIs available on RapidAPI.
- Game Database API – The Game Database API is an API for IGDB.com (which is a popular video gaming community website for game consumers and game developers). It exposes various endpoints that provide a list of video games, game release dates, game characters, and much more.
- Poke API – The Poke API is an API for the Pokemon series video games. It provides various endpoints that expose information about pokemon moves, their abilities, encounters, and much more.
- Dota 2 API – Dota 2 is a multiplayer online game. The Dota 2 API is an API for Dota 2. It provides information about teams, matches, tournaments, players, etc.
- CheapShark Game Deals API – The CheapShark Game Deals API is a price comparison API for digital games. It provides information about all deals available across multiple stores, information about a specific deal, etc.
- Minecraft API – Minecraft is another very popular online video game. The Minecraft API is an API for Minecraft. It exposes various endpoints that allow interacting with Minecraft servers.
Summary
So, to summarize, RAWG is a video games database that provides metadata about video games. The RAWG Video Games Database API is a REST API for RAWG. It exposes endpoints that allow obtaining information about games, genres, platforms, game developers, and much more. In this article, we learned about all the endpoints that this API provides. We also learned how we can use RapidAPI to connect to the API obtain code snippets in different programming languages and execute the API endpoints.
Leave a Reply