DEV Community

NikitaL2022
NikitaL2022

Posted on

Wikipedia API's and 'wikipedia-query' through fetch()

fetch()

  • The tag fetch() will execute the API based on this link
    (this.locationEndpoint + userIPData.ip). If the call is works, then it will return the data object as a json and it will have long, lat, city, and state properties which we assign to corresponding properties in our class LocationFromIP.

  • When we render html, these properties will be used as values for input box, google maps link, and Wikipedia search parameters.

Image description

API

  • This API https://freegeoip.app/json/ requires concatenating the link with IP address and fetching the returning data object. Here is where you can learn more about Wikipedia API.

Image description

  • For my project, the API doesn't work and returns nothing, so I had to hardcode the properties to show how the website would look if the API would work. This link https://freegeoip.app/ says you need to obtain API key, which needs to be added to the end of the API call.

Image description

Wikipedia-query

  • Wikipedia-query is very simple. All that's needed to do is pass values for the search parameters.
    Image description

  • Interestingly, passing State College as a parameter doesn't generate any return for just city, but adding the state helps.

Image description

My Work

  • Here is where you can see my work and look more into the code.

Top comments (0)