ExpDev07 / coronavirus-tracker-api

🦠 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!
https://coronavirus-tracker-api.herokuapp.com
GNU General Public License v3.0
1.59k stars 323 forks source link

Creational design pattern #432

Closed bjy19 closed 3 years ago

bjy19 commented 3 years ago

Why I used it. In this API we have to decide first that from which source we are going to get all data. if we do not decide then it will give data from the default source. Here once you define the source then it will remain the same for all user endpoints. So it is better to use a singleton.

How I made it. I have added a singleton pattern in the source at the data/__init__.pyfile. And I am creating a singleton instance inside the main.pyfile. And the use of this instance is the second router v2.py for getting data from the source.