🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

github.com/BHAVYAghub/Youtube-API

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/BHAVYAghub/Youtube-API

v0.0.0-20220925192446-d8c9ab2c4644
Source
Go
Version published
Created
Source

YouTube API

A Golang application which shows Youtube videos data of any search query. Database will be filled with new data calling youtube API every minute using a cron job.

Project tech Info:

  • Language: Project is build in Golang.
  • DataBase:
    • MongoDB is used as the database for this project.
    • Indexing:
      • publishedAt: field is indexed to fetch sorted video data on the basis of the published Date.
      • Title & description: text index is used on video title and description to provide 'Fuzzy Search' on these fields.
  • Containerization:
    • Docker has been used to containerize the application.
    • MongoDB and Application have been containerized in docker-compose file.

Approach used:

  • Cron scheduler has been configured to run periodically and fetch the data from Youtube and stored in mongoDB.
  • GET endpoints have been configured to fetch data from database and display results in paginated format sorted by video published time.
  • Fuzzy search support has been added by adding text index on video title and description.
  • Multiple API keys support is provided. Config accepts commma separated api keys.

Steps to run the application:

  • Set configs in .env file.
With Docker:
  • Just run this command docker compose up --build
Without Docker:
  • Setup Mongo DB in your local machine.
  • Setup Golang in your local machine.
  • Open .env file in project's root directory. And Provide all the configs mentioned.
  • Run go run main.go command in project's root directory.

Note:

  • Server will be up and running on localhost port 8000 [by default].
  • while using docker approach, make sure localhost is set to db in MONGO_URI config present in .env file due to container network.

Configs Info:

The following configs are to be set in .env file.
See .env file for example values.

NameDescription
MONGODB_URIDescribes the mongoDB connection URI.
MONGODB_COLLECTION_NAMEDescribes the mongoDB connection name.
MONGODB_DATABASE_NAMEDescribes the mongoDB database name.
YT_API_KEYDescribes the API-keys to be used for calling YT endpoints. comma separated API keys. (next key will be used when one is exhausted)
YT_QUERY_STRINGDescribes the query string to be used to fetch YT records and save in DB.
YT_API_BASE_URLDescribes the YT Api Base URL.
YT_FETCH_RECORDS_AFTERDescribes the time after which the YT records are to be fetched and saved.
YT_API_FETCH_INTERVALDescribes the interval to call the scheduler to fetch youtube records in minutes. (default 1)
PORTDescribes the port on which application will run.
DISABLE_CRONkill switch to disable the youTube data fetching scheduler. (default false)

Rest Endpoints details:

  • The GET endpoints mentioned below supports pagination via query params.
    • page default as 1.
    • limit default as 5.
METHODENDPOINTDescription
GET/youtube/findAllFetches the youtube records saved in DB, sorted in reverse chronological order of their publishing date-time.
GET/youtube/findFetches the youtube records saved in DB, sorted in reverse chronological order of their publishing date-time on the basis of search query param (fuzzy serach).

Note:

  • Carefully set the YT_FETCH_RECORDS_AFTER config as this might exhaust your quota.

  • Set the configs before running the application.

  • Api keys are considered as secret. For security purposes, API keys have not been logged anywhere.

FAQs

Package last updated on 25 Sep 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts