API Integration

List of External APIs Used:

YouTube Data API v3

  • Endpoint: https://www.googleapis.com/youtube/v3/search
  • Purpose: Fetches search results from YouTube based on user queries.

Handling the Requests

Validation:

  • The route first checks if searchQueries is a valid array and not empty.
  • If the validation fails, it responds with a 400 status and an error message.

Processing the Queries:

  • Filters out any empty queries.
  • For each valid query, sends a GET request to the YouTube Data API endpoint.
  • Uses Axios for making the HTTP requests.
  • Handles errors for each request individually to ensure that one failed request doesn't affect the others.

Collecting the Responses:

  • Uses Promise.all to wait for all the requests to complete.
  • Groups the results by the user who made the query.
  • Returns the aggregated results in the response.

Error Handling:

  • Logs errors encountered during API requests.
  • Returns an empty array of videos for users whose requests failed.
  • Responds with a 500 status and an error message if there is a server-side issue.

Cloudinary API

Endpoints:
  • cloudinary.uploader.upload_stream: Used to upload images to Cloudinary.
  • cloudinary.url: Generates a signed URL for accessing the uploaded image.
  • cloudinary.uploader.destroy: Deletes images from Cloudinary.
Purpose:
  • Manages image uploads, retrievals, and deletions in Cloudinary for user profile pictures.