- Introduction
- Technologies Used
- How to Run
- Setting Up Environment Variables
- Endpoints
- Authentication and Authorization
- How to Use
This API provides functionality for a URL shortening service. Users can register, login, generate short URLs, and access administrative features.
You can find the Postman collection for this API here.
- Node.js
- Express.js
- MongoDB (or your preferred database)
- JSON Web Tokens (JWT) for authentication
- bcrypt for password hashing
- Clone this repository.
- Install dependencies with
npm install
. - Set up your environment variables (e.g., database connection, JWT secret).
- Run the server with
npm start
.
Create a .env
file in the root directory of the project and add the following variables:
PORT=3000
MONGODB_URI=mongodb://localhost:27017/your_database_name
JWT_SECRET=your_secret_key
POST /api/v1/register
: Register a new user.POST /api/v1/login
: Log in as an existing user.POST /api/v1/logout
: Log out the logged-in user.GET /api/v1/profile
: Get the profile of the logged-in user.PATCH /api/v1/profile/u
: Update the profile of the logged-in user.DELETE /api/v1/profile/d/
: Delete the profile of the logged-in user.POST /api/v1/forgetpassword
: Initiate password reset process.POST /api/v1/resetpassword
: Reset the password using the token.GET /api/v1/resetpassword
: Render password reset page.
POST /api/v1/createshorturl
: Generate a short URL for a given long URL.GET /api/v1/user/url
: Get all URLs created by the logged-in user.GET /api/v1/user/url/:id
: Get a specific URL created by the logged-in user.DELETE /api/v1/user/url/d
: Delete a specific URL created by the logged-in user.
GET /api/v1/admin
: Get the profile of the admin user.GET /api/v1/admin/getalluser
: Get all users (admin access required).GET /api/v1/admin/getallurldetails
: Get all URLs with metrics (admin access required).DELETE /api/v1/admin/user/d/
: Delete a user (admin access required).DELETE /api/v1/admin/url/d
: Delete a URL (admin access required).
- Authentication is required for most endpoints using JWT tokens.
- Some endpoints require admin privileges for access.
- Register a new user using
POST /api/v1/register
. - Log in using
POST /api/v1/login
to obtain a JWT token. - Use the token to access protected endpoints.
- Generate short URLs using
POST /api/v1/createshorturl
. - Admins can access additional endpoints for user management.