A backend system built using FastAPI + MongoDB Atlas + JWT Authentication that allows users to securely generate, manage, and track API keys with usage monitoring.
- 🔐 User Registration & Authentication
- ♻️ Access & Refresh Token System
- 🔑 API Key Creation & Management
- 📊 API Usage Tracking
- ⏱️ Middleware for Request Timing
- 🌐 MongoDB Atlas Cloud Database Integration
- Backend: FastAPI
- Database: MongoDB Atlas
- Authentication: JWT (Access + Refresh Tokens)
- Language: Python
-
POST
/auth/register👉 Register new user -
POST
/auth/login👉 Login user → returns Access Token + Refresh Token -
POST
/auth/refresh👉 Generate new access token using refresh token
⚠️ All below endpoints require valid Access Token
-
POST
/Api_Mangement/create👉 Create new API key -
GET
/Api_Mangement/view👉 Get all API keys -
GET
/Api_Mangement/view/{api_id}👉 Get single API key -
DELETE
/Api_Mangement/delete/{api_id}👉 Delete API key -
PUT
/Api_Mangement/update/{api_id}👉 Update API key status (Active / Inactive)
- GET
/usage_tracker/call_api👉 Send URL as string → store in database
git clone https://github.com/your-username/your-repo.git
cd your-repo
python -m venv myenv
myenv\Scripts\activate # Windows
pip install -r requirements.txt
Create .env file:
MONGO_URL=mongodb+srv://username:password@cluster.mongodb.net/Smart_api_mangement_system
DB_NAME=Smart_api_mangement_system
SECRET_KEY=your_secret_key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=20
REFRESH_TOKEN_EXPIRE_DAYS=7
uvicorn app.main:app --reload
Open browser:
http://127.0.0.1:8000/docs
- Use
/auth/register - Provide username & password
-
Use
/auth/login -
Get:
- Access Token
- Refresh Token
copy Access Token
Enter the Access Token Format:
Bearer <your_access_token>
Now you can:
- Create API key
- View API keys
- Update / Delete API key
If access token expires:
- Call
/auth/refresh - Get new access token
- Call
/usage_tracker/call_api - Send URL as string :
example : /ApiKey/home/profile
- Data stored in MongoDB
Give it a ⭐ on GitHub!