Skip to content

About

Wikipedia API wrapper

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

Repository files navigation

Wikipedia API Wrapper

Author: Magda Kowalska

How to run the app

Assuming you have Docker running on your machine, you can simply run the app by running

make run

inside the root directory of the project.

Once it's done building, the app's API is accessible at http://0.0.0.0:80

(If you don't have Docker, please Google how to install it on your machine)

Endpoints

To see the autogenerated OpenAPI documentation you can go to http://0.0.0.0:80/docs on your browser. Otherwise, refer to the sample responses below.

GET /api/top

http://0.0.0.0:80/api/top?cadence=weekly&limit=10&start_date=2023-4-20

Response:

{
    "start_date": "2023-04-20",
    "end_date": "2023-04-26",
    "limit": 10,
    "language": "en",
    "top_views": {
        "Main_Page": 32404223,
        "Special:Search": 9365859,
        "Indian_Premier_League": 2951954,
        "ChatGPT": 2065592,
        "2023_Indian_Premier_League": 1897497,
        "Wikipedia:Featured_pictures": 1560788,
        "Cleopatra": 1432788,
        "Kisi_Ka_Bhai_Kisi_Ki_Jaan": 1276217,
        "Evil_Dead_Rise": 1183817,
        "Harry_Belafonte": 1099797
    }
}

GET /api/top/{article_name}

http://0.0.0.0:80/api/top/ChatGPT?cadence=weekly&start_date=2023-4-20

Response:

{
    "article_name": "ChatGPT",
    "start_date": "2023-04-20",
    "end_date": "2023-04-26",
    "language": "en",
    "all_views": 2065592,
    "most_viewed_date": "2023-04-25",
    "most_viewed_date_views": 383693
}

How to run tests

Make sure your container is still running.

Execute

make console

Inside the Python shell enter those two lines

import pytest
pytest.main(["-x","/code/tests"])

and press Enter.

Performance implications and what would I want to do in production

  1. When running the GET /api/top endpoint with cadence=monthly it takes a while to get a response. This is because we make 30 calls and for each call we have to process 1000 records. To achieve better performance, the calls to the Wikipedia endpoint for each day and processing of the daily data could be done in parralel threads and then concatenated into a final response.

  2. According to Wikimedia API docs as an Annonymous User we can only make 500 requests per hour. If we wanted to productionize this API Wrapper we should definitely consider becoming an authenticated user/app to increase our limits to 5000 requests per hour. If this is not enough, we would need to contact Wikimedia and request special access of sorts.

  3. I would add Prometheus metrics monitoring while making this API Wrapper production ready in order to observe the performance and state of my API.

  4. Depending on how this API Wrapper is intended to be used, I would introduce some kind of Authentication protocol to only limit the usage of my API to known consumers. Adding a Bearer Token requirement in the Authorization header would be pretty straightforward.

About

Wikipedia API wrapper

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages