tiny-url-nestjs-microservice/README.md

66 lines
1.8 KiB
Markdown
Raw Normal View History

2024-01-22 13:36:28 +00:00
# Tiny URL Microservice
2024-01-21 08:19:18 +00:00
2024-01-22 13:36:28 +00:00
The Tiny URL Microservice is a simple URL shortening service built with Nest.js. It allows users to create shortened versions of long URLs, making them easier to share. This README provides an overview of the project, how to run it, and details about available routes.
2024-01-21 08:19:18 +00:00
2024-01-22 13:36:28 +00:00
## Table of Contents
2024-01-21 08:19:18 +00:00
2024-01-22 13:36:28 +00:00
- [Project Overview](#project-overview)
- [Prerequisites](#prerequisites)
- [Getting Started](#getting-started)
- [API Routes](#api-routes)
- [Testing](#testing)
2024-01-21 08:19:18 +00:00
2024-01-22 13:36:28 +00:00
## Project Overview
2024-01-21 08:19:18 +00:00
2024-01-22 13:36:28 +00:00
This project is a simple URL shortening microservice built with Nest.js. It provides the following features:
2024-01-21 08:19:18 +00:00
2024-01-22 13:36:28 +00:00
- URL Shortening: Convert long URLs into short, easy-to-share versions.
- URL Expansion: Expand shortened URLs to their original long form And redirect users to the original URL.
2024-01-21 08:19:18 +00:00
2024-01-22 13:36:28 +00:00
## Prerequisites
Before you begin, ensure you have met the following requirements:
- Node.js installed on your machine.
- Docker and Docker Compose (if you prefer to use Docker).
- `.env` file (if not using Docker) with the necessary environment variables. You can use .env.exmaple as a reference.
2024-01-21 08:19:18 +00:00
2024-01-22 13:36:28 +00:00
## Getting Started
2024-01-21 08:19:18 +00:00
2024-01-22 13:51:29 +00:00
To get the project up and running, Choose one of the options and follow the instructions below.
2024-01-21 08:19:18 +00:00
2024-01-22 13:48:40 +00:00
### 1. Using Docker Compose
2024-01-21 08:19:18 +00:00
2024-01-22 13:38:39 +00:00
```bash
docker-compose -f docker-compose.yaml up -d --build
2024-01-22 13:36:28 +00:00
```
2024-01-21 08:19:18 +00:00
2024-01-22 13:51:29 +00:00
### Or
2024-01-22 13:46:57 +00:00
2024-01-22 13:48:40 +00:00
### 2. Using Dev Environment
2024-01-22 13:46:57 +00:00
2024-01-22 13:48:40 +00:00
run `npm run start:dev` to start the server.
2024-01-22 13:46:57 +00:00
2024-01-22 13:51:29 +00:00
### Your Nest.js server should now be running on port as like the port from the .env file.
2024-01-22 13:46:57 +00:00
2024-01-22 13:36:28 +00:00
## API Routes
# Shorten URL:
2024-01-21 08:19:18 +00:00
2024-01-22 13:36:28 +00:00
- Endpoint: POST /url-shortener/shorten
- Request Body: { "url": "https://example.com" }
- Response: { "data": "abc123", "status": 201 }
Expand URL:
Endpoint: GET /url-shortener/:shortUrl
Response: Redirects to the original long URL or redirect to the client UI 404 page if not found.
## Testing
To run the tests, run the following command:
```bash
npm run test
```