Welcome to the User Management API documentation! This API provides endpoints for managing users, their subscriptions, and related resources such as API keys and plans.
- Overview
- Installation
- API Endpoints
- Exception Handling
- Authentication
- Pagination
- Testing
- Contributing
- License
The User Management API provides a suite of endpoints to manage user accounts, subscriptions, plans, and API keys. It uses NestJS and MongoDB for backend operations and follows RESTful principles.
-
Clone the repository:
git clone https://github.com/Rexsunon/user-management-api.git
-
Navigate to the project directory:
cd user-management-api
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env
file in the root directory and provide the necessary configuration:PORT=6969 MONGO_URI=mongodb://localhost:27017/user-management JWT_SECRET=your_jwt_secret RATE_LIMIT_TTL= RATE_LIMIT_LIMIT= ADMIN_EMAIL= ADMIN_PASSWORD=
-
Run the application:
npm run start
-
Run tests (optional):
npm run test
-
Create User
- Endpoint:
POST /users
- Description: Creates a new user and assigns a default plan.
- Request Body:
{ "email": "user@example.com", "password": "string", "otp": "string", "name": "string" }
- Endpoint:
-
Find All Users
- Endpoint:
GET /users
- Description: Retrieves a paginated list of all users.
- Query Parameters:
page
(optional): Page number (default: 1)limit
(optional): Number of users per page (default: 10)
- Endpoint:
-
Find One User
- Endpoint:
GET /users/:id
- Description: Retrieves a user by their ID.
- Endpoint:
-
Update User
- Endpoint:
PUT /users/:id
- Description: Updates user details.
- Request Body:
{ "email": "user@example.com", "password": "string", "name": "string" }
- Endpoint:
-
Delete User
- Endpoint:
DELETE /users/:id
- Description: Deletes a user by their ID.
- Endpoint:
-
Validate Password
- Endpoint:
POST /users/:id/validate-password
- Description: Validates a user's password.
- Request Body:
{ "password": "string" }
- Endpoint:
-
Create Subscription
- Endpoint:
POST /subscriptions
- Description: Creates a new subscription for a user.
- Endpoint:
-
Find Subscription by User ID
- Endpoint:
GET /subscriptions/:userId
- Description: Retrieves an active subscription by user ID.
- Endpoint:
-
Find All Subscriptions
- Endpoint:
GET /subscriptions
- Description: Retrieves a paginated list of all subscriptions.
- Query Parameters:
page
(optional): Page number (default: 1)limit
(optional): Number of subscriptions per page (default: 10)
- Endpoint:
-
Update Subscription
- Endpoint:
PUT /subscriptions/:userId
- Description: Updates the subscription plan for a user.
- Endpoint:
-
Create Plan
- Endpoint:
POST /plans
- Description: Creates a new plan.
- Request Body:
{ "name": "string", "description": "string", "tag": "string", "monthlyApiCallLimit": 0, "price": 0, "durationInMonths": 0, "unlimited": false }
- Endpoint:
-
Find All Plans
- Endpoint:
GET /plans
- Description: Retrieves a paginated list of all plans.
- Query Parameters:
page
(optional): Page number (default: 1)limit
(optional): Number of plans per page (default: 10)
- Endpoint:
-
Find Plan by ID
- Endpoint:
GET /plans/:id
- Description: Retrieves a plan by its ID.
- Endpoint:
-
Update Plan
- Endpoint:
PUT /plans/:id
- Description: Updates plan details.
- Request Body:
{ "name": "string", "description": "string", "tag": "string", "monthlyApiCallLimit": 0, "price": 0, "durationInMonths": 0, "unlimited": false }
- Endpoint:
-
Delete Plan
- Endpoint:
DELETE /plans/:id
- Description: Deletes a plan by its ID.
- Endpoint:
-
Create API Key
- Endpoint:
POST /apikeys
- Description: Generates a new API key for a user.
- Endpoint:
-
Validate API Key
- Endpoint:
POST /apikeys/validate
- Description: Validates if the provided API key is valid.
- Request Body:
{ "apiKey": "string" }
- Endpoint:
The API uses standard HTTP status codes to indicate success or failure:
200 OK
- The request was successful.201 Created
- A resource was successfully created.400 Bad Request
- The request was invalid or malformed.401 Unauthorized
- Authentication is required or failed.403 Forbidden
- The request is understood but refused.404 Not Found
- The requested resource could not be found.500 Internal Server Error
- An unexpected error occurred on the server.
The API does not require authentication for most endpoints, but API keys are used for access control. Ensure that your requests include valid API keys where necessary.
For endpoints that return lists of resources, pagination is implemented using page
and limit
query parameters:
page
: The page number (default is 1).limit
: The number of items per page (default is 10).
To run tests, ensure you have all dependencies installed and then execute:
npm run test
Contributions are welcome! Please open an issue or a pull request on GitHub if you have suggestions or improvements.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes.
- Commit your changes (
git commit -am 'Add feature'
). - Push to the branch (
git push origin feature-branch
). - Open a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
Feel free to customize the sections and examples according to your specific API requirements and any additional details relevant to your project.