Using APIs can be super powerful in making a website and today we are going to learn how to use APIs to be able to use the wikipedia-query tag so we can display a wikipedia article for whatever your heart desires. Before we go further, what is an API?
An API is short for application programming interface is a connection between computers or programs that allows it to communicate with a server or data base.
My repository that I will be referring to is linked here
Getting started with Fetch
We are going to communicate with the API by using fetch. What this brick of code does is basically ask to go get the data from the users IP and then store it in variables that we will use later.
Using the tag
Once we have the data we can use it to put the search terms directly into the search. Here we have some basic set up and "backbone" that powers the search but then the wikipedia query just follows the format of <wikipedia-query search="${this.city}, ${this.state} "></wikipedia-query> with an option to exclude a city or a state to have a more specific article brought up as shown in the code3 below.

In summation, we are accessint the data from the users IP, using the API to dissect the information returned and storing it, then we use the wikipedia query to search for the article. Happy coding :)


Top comments (0)