Run the $ docker-compose up command to start the service.
And then run migrations $ docker-compose exec web python manage.py migrate
Also create the super user $ docker-compose exec web python manage.py createsuperuser
🔐 Environment variables:
Create file .env inside youtube-api directory
Copy contents from .env.example file and paste it in the .env file you just created.
After copying the contents, edit the SECRET_KEY.
You can generate SECRET_KEY using get_random_secret_key method.
Run $ django-admin shell in the terminal.
Enter $ from django.core.management.utils import get_random_secret_key to import the method.
And then enter $ secret_key = get_random_secret_key() to generate the secret key.
You can now use the generated value as our SECRET_KEY.
Functionality
Youtube API is used to fetch latest videos for a predefined query.
Server call the YouTube API continuously in background (async) with some interval (say 10 seconds)
The latest videos are stored in the database.
A GET API which returns the stored video data in a paginated response sorted in descending order of published datetime.
A search API to search the stored videos using their title and description.
Support for supplying multiple API keys so that if quota is exhausted on one, automatically the next available key is used.
Note
Atleast one Youtube API key should be added in the database using the endpoint http://localhost:8000/youtube/api-key/ to fetch and save the video details.
API Enpoints
1. API to add Youtube API Key in the database.
Post request will add Youtube API key in the database
http://127.0.0.1:8000/youtube/api-key/
Body
{
"api_key":"AIzaSyC5iiJjJzX_MAYsss5f3TTZzTvC4"
}
Response
"API key added successfully"
2. API to get stored youtube videos.
Get API will return paginated JSON response in descending order of the published datetime.