Welcome to the URL Shortener Service! This service is designed to shorten URLs and provide basic statistics on their usage. The system is divided into two microservices: the URL Shortener and the Token Service.
- Languages: TypeScript, JavaScript
- Databases: MongoDB
- Cache: Redis
- Frameworks/Libraries: Mongoose, NestJS
- Tools: Postman, VScode
This microservice handles the core functionality of shortening URLs and retrieving statistics.
-
Create Short URL
- Method: POST
- Path:
/shortener/create/{url} - Description: Shortens the provided URL and returns a unique short code.
-
Retrieve Original URL
- Method: GET
- Path:
/shortener/{short_code} - Description: Retrieves the original URL associated with the given short code.
-
Retrieve URL Statistics
- Method: GET
- Path:
/shortener/{short_code}/stats - Description: Provides statistics for the given short code, including the number of visits and other relevant data.
This microservice is responsible for handling tokens, which may be used for various authentication purposes.
- Retrieve Token
- Method: GET
- Path:
/token - Description: Generates and returns a token for authentication purposes.
To set up and run the URL Shortener Service, follow these steps:
-
Clone the repository:
git clone https://github.com/your-repo/url-shortener-service.git
-
Navigate to the project directory:
cd url-shortener-service -
Install dependencies:
npm install
-
Start the microservices:
-
URL Shortener Microservice (Port: 3000):
npm run start:dev
-
Token Service Microservice (Port: 4000):
npm run start:dev
-
-
Create a Short URL:
POST http://localhost:3000/shortener/create/{url}
Example:
POST http://localhost:3000/shortener/create/https://example.com
-
Retrieve Original URL:
GET http://localhost:3000/shortener/{short_code}
Example:
GET http://localhost:3000/shortener/abc123
-
Retrieve URL Statistics:
GET http://localhost:3000/shortener/{short_code}/stats
Example:
GET http://localhost:3000/shortener/abc123/stats
-
Retrieve Token:
GET http://localhost:4000/token
Example:
GET http://localhost:4000/token
For certain actions, authentication may be required using the token provided by the Token Service.