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.
- Python (Django, DRF)
- Postgres
- Celery
- Celery Beat
- Redis -> Broker
curl request with default pagination:-
curl --location --request GET 'http://127.0.0.1:8000/youtube/getVideos'
curl request with passing page limit in query params:-
curl --location --request GET 'http://127.0.0.1:8000/youtube/getVideos?page_limit=15'
curl request:-
curl --location --request GET 'http://127.0.0.1:8000/youtube/searchVideos?query=puri food'
curl request:-
curl --location --request POST 'http://127.0.0.1:8000/youtube/addAuthKey' \
--header 'Content-Type: application/json' \
--data-raw '{
"auth_key": "your_key"
}'
I have dockerize the project as mentioned in the assignment requirements. So it is simple to run the project through docker.
- Clone the project
- Should have docker installed on the system (If not, download it from official site)
- Move to the root of project
- Run command
$ docker-compose build
- Then Run
$ docker-compose up
Project will start running in docker container
As soon as you run the project in docker, cron job will start every 30 sec and try to fetch data from youtube. But as there is no auth key in database, it will throw error no api key found
So as a next step, hit the 3rd API (Add Auth Key API) with valid api key and wait for atleast 30 seconds as scheduler will run every 30 seconds.
Now you can test 1st and 2nd API as well
For this task I have used django admin portal, which provides all the feature liking listing of video, filtering, sorting etc.
To see dashboard, we have to first create superuser. Run the below command to create superuser
$ docker-compose run app python manage.py createsuperuser
It will ask User, email and password. After entering all the details, hit the below url in any browser
127.0.0.1:8000/admin/
Login with the credentials and check the dashboard for videos