Introduction to Age of Empires 2 API

The Age of Empires 2 API is a free, public API that provides access to information about the units, civilizations, technologies, and other game elements in Age of Empires 2. The API is hosted on Heroku and provides data in JSON format.

In this blog post, we will explore the Age of Empires 2 API and demonstrate how to use it with JavaScript. Let's get started!

Exploring the API

To start using the API, we need to explore the available endpoints and data structures. The API documentation is available at https://age-of-empires-2-api.herokuapp.com/docs/.

The documentation provides clear descriptions of each endpoint, the parameters they accept, and the data they return.

For example, let's look at the "civilizations" endpoint. This endpoint returns a list of all the civilizations in the game along with their associated data, such as unique units and technologies. The API endpoint URL is https://age-of-empires-2-api.herokuapp.com/api/v1/civilizations.

Using the API with JavaScript

To use the Age of Empires 2 API with JavaScript, we can make HTTP requests to the API endpoints using the Fetch API.

Here is an example of how to retrieve data from the "civilizations" endpoint and log it to the console:

fetch("https://age-of-empires-2-api.herokuapp.com/api/v1/civilizations")
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error));

This code makes a GET request to the "civilizations" endpoint and retrieves the data as a JSON object. It then logs the data to the console. If an error occurs, it is also logged to the console.

Conclusion

In this blog post, we explored the Age of Empires 2 API and demonstrated how to use it with JavaScript. The API provides a wealth of information about the game, and its endpoints are easy to access and understand.

Try exploring the API documentation and experimenting with different endpoints and parameters to discover the many possibilities of this great API.

Related APIs