🦠A simple and fast (< 200ms) API for tracking the global coronavirus (COVID-19, SARS-CoV-2) outbreak. It's written in python using the 🔥 FastAPI framework. Supports multiple sources!
Why I used it.
In this API there are three different classes called csbc.py, jhu.py, and nyt.py from where we get all data. Here we need to call 3 different types of methods for getting same data. That's why I created an adapter that provides data from the appropriate source with one single method.
How I made it.
In the services/location/__init__.py file I made an adapter class called LocationService. This class provides two common methods for any type of source. The name of these methods are get_all() and get(). I am storing the object of adapter classes inside the request.state.source. Hence when we call it from router v2.py then we only need to watch the methods of the adapter.
Why I used it. In this API there are three different classes called csbc.py, jhu.py, and nyt.py from where we get all data. Here we need to call 3 different types of methods for getting same data. That's why I created an adapter that provides data from the appropriate source with one single method.
How I made it. In the
services/location/__init__.py
file I made an adapter class called LocationService. This class provides two common methods for any type of source. The name of these methods areget_all(
) andget()
. I am storing the object of adapter classes inside therequest.state.source
. Hence when we call it from routerv2.py
then we only need to watch the methods of the adapter.