This repository contains a URL shortener microservice API that allows you to shorten long URLs into shorter, more manageable links. This README file provides an overview of the API and instructions for setting it up and using it.
- Shorten long URLs into shorter links.
- Redirect shortened links to their original URLs.
- Track the number of clicks on each shortened link.
To run this microservice API, you need to have the following software installed on your system:
- Node.js (version 10 or higher)
- npm (Node Package Manager) or yarn
- MongoDB (version 3.6 or higher)
-
Clone this repository to your local machine using the following command:
git clone https://github.com/usefsame7/URL-Shortener-Microservice-API.git -
Navigate to the project directory:
cd URL-Shortener-Microservice-API -
Install the required dependencies by running either of the following commands:
npm installor
yarn install -
Create a
.envfile in the root of the project and provide the necessary configuration parameters. You can use the.env.examplefile as a template. Make sure to set the appropriate values for the following variables:MONGODB_URI: Connection URI for your MongoDB database.BASE_URL: Base URL for your microservice API (e.g.,http://localhost:3000).
-
Start the API server by running:
npm startor
yarn start -
The API server should now be running locally on the specified port (default: 3000).
To use the URL shortener microservice API, you can send HTTP requests to the available endpoints. You can use tools like cURL, Postman, or any programming language/library that supports making HTTP requests.
The API exposes the following endpoints:
-
POST /api/shorturl
Creates a shortened URL from a long URL.
Request body:{ "url": "https://www.example.com/very/long/url" }Response:
{ "originalUrl": "https://www.example.com/very/long/url", "shortUrl": "http://localhost:3000/abc123", } -
GET /api/shorturl/:id
Redirects the user to the original URL associated with the provided short URL code.
Response: Redirects to the original URL.
If you have any questions or suggestions regarding this project, please feel free to contact the project owner:
- Name: Youssef Sameh Elsisy
- Email: yousameh2006@gmail.com
Regards.Y