Code Monkey home page Code Monkey logo

brainflix_back's Introduction

Video Platform API

This project is a simple API for managing a video platform built with Express.js. It allows for uploading, retrieving, and managing videos and their associated comments.

Features

  • Video Management: Upload and retrieve videos with associated metadata.
  • Comment System: Add and delete comments on videos.
  • API Key Security: Secure endpoints with an API key middleware.
  • File Upload: Use multer for handling image uploads.
  • Static Files: Serve static images and videos.

Setup

  1. Clone the repository:

    git clone https://github.com/Martikk/BrainFlix_back
    cd videoplatform
  2. Install dependencies:

    npm install
  3. Create a .env file:

    echo "API_KEY=yourapikey" > .env
  4. Run the server:

    npm start

API Documentation

For detailed information on how to use the API, please refer to the API Documentation.

Using the API

  1. Register for an API Key:

    To register with the API and get a key, make a GET request to /register. You can do this with your browser, and you only need to do it once. Store the key in a global variable in your website.

    GET https://brainflixback-f347c94ccf8f.herokuapp.com/register

    Example response:

    {
      "api_key": "your_generated_api_key"
    }
  2. Include the API Key in Requests:

    For each of your API requests (except for /register), append ?api_key=your_api_key to the URL.

API Endpoints

GET /videos

Retrieve a list of all videos.

GET /videos/:id

Retrieve a specific video by ID.

POST /videos

Upload a new video. This endpoint expects an image file and metadata (title, description).

POST /videos/:id/comments

Add a new comment to a video.

DELETE /videos/:id/comments/:commentId

Delete a comment from a video.

POST /videos/:id/like

Like a video.

Code Explanation

Middleware

  • CORS: Enabled to allow cross-origin requests.
  • API Key Middleware: Secures the endpoints by checking for a valid API key in the query string or headers.

File Upload

  • Multer: Configured to store images in the public/images directory with a unique filename.

Data Management

  • readData(): Reads the JSON file (data.json) containing video information.
  • writeData(): Writes data to the JSON file.

Routes

  • GET /videos: Retrieves and returns all videos, with image and video URLs formatted correctly.
  • GET /videos/:id: Retrieves a specific video by ID.
  • POST /videos: Handles the upload of a new video, storing metadata and the uploaded image.
  • POST /videos/:id/comments: Adds a comment to a specific video.
  • DELETE /videos/:id/comments/:commentId: Deletes a specific comment from a video.
  • POST /videos/:id/like: Increments the like count of a specific video.

Challenges

  • Security: Implementing API key security to protect the endpoints from unauthorized access.
  • File Handling: Managing file uploads and ensuring files are stored and retrieved correctly.
  • Data Management: Reading from and writing to a JSON file, ensuring data integrity and proper formatting.

Improvements

  • Database Integration: Replace the JSON file with a database for better performance and scalability.
  • Authentication: Implement user authentication and authorization for more secure and personalized API access.
  • Error Handling: Improve error handling and validation to provide more informative responses and handle edge cases.

Contributing

Feel free to open issues or submit pull requests for any improvements or bug fixes.

brainflix_back's People

Contributors

martikk avatar

Watchers

Logan Masniuk avatar Jim avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.