/API-Demo

This project is an API Key Manager application developed using Node.js, Express, and MongoDB. I created this demo project to practice API creation, handling, and Docker management as part of my web application development training.

Primary LanguageJavaScriptMIT LicenseMIT

๐Ÿ”‘ API Key Manager ๐Ÿ”‘

This project is an API Key Manager application developed using Node.js, Express, and MongoDB. I created this demo project to practice API creation, handling, and Docker management as part of my web application development training. To maximize your learning, I recommend creating a new project and typing each script yourself. Simply copying and pasting won't be as effective. Just being honest here.

๐Ÿ“’ It covers:

  • ๐Ÿ“ Sign up and log in.
  • ๐Ÿ—๏ธ Generate API keys.
  • ๐Ÿ” View their API keys and usage logs.
  • โš™๏ธ Use their API keys to access a sample /multiply endpoint.

๐Ÿ“ธ Screenshots ๐Ÿ“ธ

Login Page:

Login Page

Dashboard:

Dashboard

โœจ Features โœจ

  • ๐Ÿ”’ User Authentication: Secure user signup and login with password hashing.
  • ๐Ÿ”‘ API Key Generation: Generates unique API keys for each user.
  • ๐Ÿ—‚๏ธ API Key Management: Users can view and manage their generated API keys.
  • ๐Ÿ“Š Usage Logs: Tracks API calls made with each API key.
  • ๐Ÿงช Sample API Endpoint: Provides a /multiply endpoint that demonstrates API key usage.
  • ๐Ÿณ Dockerized: Easy setup and deployment with Docker and Docker Compose.

๐Ÿš€ Getting Started ๐Ÿš€

๐Ÿ“‹ Prerequisites ๐Ÿ“‹

  • ๐Ÿณ Docker
  • ๐Ÿณ Docker Compose

โฌ‡๏ธ Installation โฌ‡๏ธ

  1. Clone the repo: git clone https://github.com/your-username/api-key-manager.git
  2. Navigate to the directory: cd api-key-manager
  3. Run: docker-compose up -d

โ–ถ๏ธ Usage โ–ถ๏ธ

  1. Access the app: http://localhost:3000.
  2. Sign up or log in.
  3. Generate API keys and view usage logs on the dashboard.
  4. Use your API keys to access the /multiply endpoint.

๐Ÿ’ป API Endpoints ๐Ÿ’ป

  • /auth/signup (POST): Creates a new user account.
  • /auth/login (POST): Logs in an existing user.
  • /api/create-api-key (POST): Generates a new API key.
  • /api/user-data (GET): Retrieves API keys and usage logs.
  • /multiply (POST): Multiplies two numbers (requires API key).
๐Ÿ“‚ Project Structure
api-key-manager/
โ”‚
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ config/
โ”‚   โ”‚   โ””โ”€โ”€ database.js           # ๐Ÿ—„๏ธ Database connection configuration
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ controllers/
โ”‚   โ”‚   โ”œโ”€โ”€ authController.js     # ๐Ÿ’‚ User authentication logic
โ”‚   โ”‚   โ”œโ”€โ”€ apiKeyController.js   # ๐Ÿ—๏ธ API key management logic
โ”‚   โ”‚   โ””โ”€โ”€ multiplyController.js # ๐Ÿงช Sample API endpoint logic
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ middleware/
โ”‚   โ”‚   โ””โ”€โ”€ auth.js               # ๐Ÿ’‚ Authentication middleware
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ models/
โ”‚   โ”‚   โ””โ”€โ”€ User.js               # ๐Ÿง‘ User model
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ”œโ”€โ”€ authRoutes.js         # ๐Ÿšช Authentication routes
โ”‚   โ”‚   โ”œโ”€โ”€ apiKeyRoutes.js       # ๐Ÿ—๏ธ API key management routes
โ”‚   โ”‚   โ””โ”€โ”€ multiplyRoutes.js     # ๐Ÿงช Sample API endpoint route
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ app.js                    # โš™๏ธ Main application file
โ”‚
โ”œโ”€โ”€ public/
โ”‚   โ”œโ”€โ”€ css/
โ”‚   โ”‚   โ””โ”€โ”€ styles.css            # ๐ŸŽจ Stylesheets
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ js/
โ”‚   โ”‚   โ””โ”€โ”€ main.js               # ๐Ÿ–ฅ๏ธ Client-side JavaScript
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ index.html                # ๐Ÿ“„ Main HTML file
โ”‚
โ”œโ”€โ”€ .dockerignore
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ Dockerfile                    # ๐Ÿณ Dockerfile for building the application image
โ”œโ”€โ”€ docker-compose.yml            # ๐Ÿณ Docker Compose configuration
โ”œโ”€โ”€ package.json                  # ๐Ÿ“ฆ Project dependencies
โ””โ”€โ”€ README.md                     # ๐Ÿ“„ This file

๐Ÿ™Œ Contributing ๐Ÿ™Œ

Contributions are welcome! Please open issues and pull requests.

๐Ÿ“„ License ๐Ÿ“„

This project is licensed under the MIT License.