A simple and efficient URL Shortener API built with Python, FastAPI, and MongoDB. Create and manage short links with a clean and fast RESTful interface.
- Create Short Links: Convert any long URL into a unique, short
ylink. - Fast Redirection: Instant redirection from short links to their original destination.
- User Authentication: Secure endpoints to manage links on a per-user basis.
- Link Management: Retrieve all links created by an authenticated user.
- Scalable: Built with modern, asynchronous tools to handle high traffic.
- Secure: Implements business logic to prevent abuse, such as limiting the number of links per user.
- Backend: Python 3.11+
- Framework: FastAPI
- Database: MongoDB (with Pymongo)
- Server: Uvicorn
- Data Validation: Pydantic
- Environment Variables: python-dotenv
Follow these instructions to get a copy of the project up and running on your local machine for development and testing purposes.
- Python 3.11 or higher
- A MongoDB database (you can use a free cluster from MongoDB Atlas)
- Git
-
Clone the repository:
git clone https://github.com/YarielZC/ylink.git cd ylink -
Create and activate a virtual environment:
# For Linux/macOS python3 -m venv venv source venv/bin/activate # For Windows python -m venv venv .\venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Create a
.envfile in the root of the project by copying the example file:cp .env.example .env
-
Open the
.envfile and fill in your environment variables. It's crucial to set your MongoDB connection string.# .env # MongoDB Connection String # Make sure to include your database name in the URL URL_DB="mongodb+srv://<user>:<password>@<cluster-url>/<db-name>?retryWrites=true&w=majority" # JWT Authentication (example) SECRET_KEY="your_super_secret_key" ALGORITHM="HS256" ACCESS_TOKEN_EXPIRE_MINUTES=30
Start the development server with Uvicorn:
uvicorn app:app --reloadThe API will be available at http://127.0.0.1:8000.
This API is fully documented using OpenAPI and Swagger UI. Once the server is running, you can access the interactive documentation in your browser to view and test all available endpoints.
- Live Documentation: https://ylink-five.vercel.app/docs
- Local Documentation:
http://127.0.0.1:8000/docs
This project is licensed under the MIT License - see the LICENSE.md file for details.
Un Acortador de URLs simple y eficiente construido con Python, FastAPI y MongoDB. Una API simple y eficiente para crear y gestionar enlaces cortos.
- Crear Enlaces Cortos: Convierte cualquier URL larga en un
ylinkcorto y único. - Redirección Rápida: Redirección instantánea desde los enlaces cortos a su destino original.
- Autenticación de Usuarios: Endpoints seguros para gestionar enlaces por usuario.
- Gestión de Enlaces: Obtén todos los enlaces creados por un usuario autenticado.
- Escalable: Construido con herramientas modernas y asíncronas para manejar alto tráfico.
- Seguro: Implementa lógica de negocio para prevenir abusos, como limitar el número de enlaces por usuario.
- Backend: Python 3.11+
- Framework: FastAPI
- Base de Datos: MongoDB (con Pymongo)
- Servidor: Uvicorn
- Validación de Datos: Pydantic
- Variables de Entorno: python-dotenv
Sigue estas instrucciones para obtener una copia del proyecto y ejecutarlo en tu máquina local para desarrollo y pruebas.
- Python 3.11 o superior
- Una base de datos MongoDB (puedes usar un clúster gratuito de MongoDB Atlas)
- Git
-
Clona el repositorio:
git clone https://github.com/YarielZC/ylink.git cd ylink -
Crea y activa un entorno virtual:
# Para Linux/macOS python3 -m venv venv source venv/bin/activate # Para Windows python -m venv venv .\venv\Scripts\activate
-
Instala las dependencias:
pip install -r requirements.txt
-
Crea un archivo
.enven la raíz del proyecto copiando el archivo de ejemplo:cp .env.example .env
-
Abre el archivo
.envy completa tus variables de entorno. Es crucial configurar tu cadena de conexión de MongoDB.# .env # Cadena de conexión de MongoDB # Asegúrate de incluir el nombre de tu base de datos en la URL URL_DB="mongodb+srv://<usuario>:<contraseña>@<url-del-cluster>/<nombre-db>?retryWrites=true&w=majority" # Autenticación JWT (ejemplo) SECRET_KEY="tu_clave_super_secreta" ALGORITHM="HS256" ACCESS_TOKEN_EXPIRE_MINUTES=30
Inicia el servidor de desarrollo con Uvicorn:
uvicorn app:app --reloadLa API estará disponible en http://127.0.0.1:8000.
Esta API está completamente documentada usando OpenAPI y Swagger UI. Una vez que el servidor esté en funcionamiento, puedes acceder a la documentación interactiva en tu navegador para ver y probar todos los endpoints disponibles.
- Documentación en vivo: https://ylink-five.vercel.app/docs
- Documentación local:
http://127.0.0.1:8000/docs
Este proyecto está bajo la Licencia MIT - mira el archivo LICENSE.md para más detalles.