This project aims to create an API for fetching the latest YouTube videos based on a predefined search query, storing them in a database, and providing paginated responses through a GET API endpoint. The project is built using Django and includes features like continuous background fetching, support for multiple API keys, and scalability.
- Clone the repository:
git clone https://github.com/ashavijit/yt-api
cd yt-api- Create a virtual environment and install dependencies:
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt-
Set up the Django environment variables:
-
Create a
.envfile in the project directory. -
Add the following environment variables to the
.envfile:SECRET_KEY=your_django_secret_key YOUTUBE_API_KEYS=your_api_key_1,your_api_key_2,your_api_key_3
-
-
Apply migrations:
python manage.py migrate- Start the Django server:
python manage.py runserver- Access the API at
http://localhost:8000/api/videos/.
GET /api/videos/: Returns the stored video data in a paginated response sorted in descending order of published datetime.
To access the dashboard for viewing stored videos with filters and sorting options:
- Ensure the Django server is running.
- Visit
http://localhost:8000/admin/in your browser. - Log in with your admin credentials.
- Navigate to the "Videos" section.
- Build the Docker image:
docker build -t youtube-video-api .- Run the Docker container:
docker run -p 8000:8000 youtube-video-api- Install Terraform from here.
- Navigate to the
terraformdirectory:
cd terraform- Initialize the Terraform working directory:
terraform init-
Create a
terraform.tfvarsfile in theterraformdirectory and add the following variables:project = "your_project_id" region = "your_region" -
Apply the Terraform configuration:
terraform apply-
Access the API at
http://<EXTERNAL_IP>:8000/api/videos/. -
Access the API at
http://localhost:8000/api/videos/.
Feel free to contribute to this project by submitting bug reports, feature requests, or pull requests.
This project is licensed under the MIT License. See the LICENSE file for details.