- Project Goal
- Running the Project Locally
- Different endpoints
- Key Features
- Video demonstration
- References
- License
To make an API to fetch latest videos sorted in reverse chronological order of their publishing date-time from YouTube for a given tag/search query in a paginated response.
- First, clone the repository to your local machine:
git clone https://github.com/Akshat-Jain/django-assignment.git
- Change the current directory to the project directory and install the requirements:
cd django-assignment
pip install -r requirements.txt
- Setup migrations and database:
python manage.py makemigrations youtube
python manage.py migrate
- Create an admin user:
python manage.py createsuperuser
Follow the prompts on the terminal to create an admin user.
- We're almost there!
There's just one more thing we need to do!
We need to create a
keys.json
file in the root directory of the project where we will store our YouTube Data API Key which will be required to fetch the videos using that API.
touch keys.json
Now open this file with any text editor.
The structure of keys.json
is required to be as follows:
{
"YOUTUBE_DATA_API_KEYS": {
"key1": "Enter your API Key 1 here",
"key2": "Enter your API Key 2 here",
"key3": "Enter your API Key 3 here",
"key4": "Enter your API Key 4 here",
}
}
You can get an API key by following this link. Make sure that you have atleast one API Key in this file with valid amount of quota left.
- Finally, run the development server:
python manage.py runserver
The project will be available at 127.0.0.1:8000.
There are 3 endpoints in the project:
/admin
: This allows user to login with the admin credentials and manage the project. The user can view the tables of the database and can also edit them directly in the provided interface./youtube/startFetching
: This endpoint triggers a background asynchronorous job to fetch information of videos. This endpoint also supports an optional query parameter to take the search query:
http://localhost:8000/youtube/startFetching?searchQuery=Cricket
http://localhost:8000/youtube/startFetching?searchQuery=Westeros
The searchQuery
is optional and defaults to Game of Thrones
if not provided.
/youtube
: This endpoint returns the stored video data in a paginated response sorted in descending order of published datetime. This endpoint also supports a query parameter to facilitate pagination as following:
http://localhost:8000/youtube/?page=1
http://localhost:8000/youtube/?page=2
.
.
http://localhost:8000/youtube/?page=pageNumber
You can find the demonstration of each of these in the Demonstration section.
- Information about YouTube videos is being fetched asynchronously as a background task on regular intervals (10 seconds as per the current implementation).
- Pagination support with latest published videos shown first.
- Stores Video ID, Title, Description, Publishing Datetime and Thumbnails URLs in the database with indexing done on
Publishing Datetime
column in reverse chronological ordering for faster access. - Support for supplying multiple API keys so that if quota is exhausted on one, it automatically uses the next available key.
- Renders the response in a custom implemented template.
The source code is released under the MIT License.