DEV Community

Cover image for Wikipedia's API and wikipedia-query
Kayra Orankoy
Kayra Orankoy

Posted on

2 2

Wikipedia's API and wikipedia-query

What is an API?

An API (Application Programming Interface) is a software that allows for connections between computers and computer programs. For this project we took advantage of Wikipedia's API's.

Fetch

fetch is a method in JavaScript that is used to request resources in the form of HTTP from a webpage. Shown below is an example of fetch being used to communicate with Wikipedia. A request is sent out with a resulting JSON response.
Image description

Wikipedia API

Before starting with Wikipedia api, make sure to import the necessary packages by adding this line of code to the top
import '@lrnwebcomponents/wikipedia-query/wikipedia-query.js';

Wikipedia has a numerous amount of functions that can be referenced here. This API allows users to connect to Wikipedia and manage different functions. With this lab we are dealing with the query function and it is accessed by using the tag wikipedia-query, it uses fetch to search for the necessary parameters.

<wikipedia-query search="${this.city}, ${this.state}"></wikipedia-query>
      <wikipedia-query search="${this.city}"></wikipedia-query>
      <wikipedia-query search="${this.state}"></wikipedia-query>
Enter fullscreen mode Exit fullscreen mode

The above block of code is three query's that get parameters filling out the state and city, the city alone, and the state alone. They were gained earlier in conjunction with the freegeoip app.

In all, API's are a useful tool that allow for coders to do less coding. Provided is my GitHub repository

API Trace View

How I Cut 22.3 Seconds Off an API Call with Sentry

Struggling with slow API calls? Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More