An open API service indexing awesome lists of open source software.

https://github.com/furkancelikk/url-shortener

URL Shortener
https://github.com/furkancelikk/url-shortener

docker-compose dockerfile exception-handling java javadoc maven mysql spring-boot unit-test url-shortener

Last synced: 4 months ago
JSON representation

URL Shortener

Awesome Lists containing this project

README

          

# URL Shortener

---

Table of Contents

* [About The Project](#about-the-project)
* [Built With](#built-with)
* [Installation](#installation)
* [Set up with Java](#set-up-with-java)
* [Set up with Docker](#setup-with-docker)

---

## About The Project

This project is a URL shortening application designed to make users'long URLs shorter and easier to remember.
Users can save their URLs along with an optional code. If a user does not provide a code,
the system will automatically generate a unique code.
Users can view these URLs using the saved code or access them directly.

---

## Built With

The following technologies, tools etc. have been used in this project:

Java
Spring Boot
MySQL
Docker
Maven
JUnit
REST
IntelliJ
Postman

---

## Installation

There are two different ways to set up the project.

### Set up with Java

> **Prerequisites**
>
> - **Java 17:** Java 17 must be installed on your local machine.
>
> - **Mysql:** You need to have a MySQL instance running on your local machine and create a schema named **url_shortener**.

1. Clone the repo

```shell
git clone https://github.com/furkancelikk/url-shortener.git
```
2. Change the directory

```shell
cd url-shortener
```
3. Pull the dependencies and build the JAR file.

```shell
mvnw clean install
```
4. Change the directory to the **target**

```shell
cd target
```
5. Start the project.

```shell
java -jar app.jar
```

You can access the project at port 8080.

**Note:** The following values are defined as environment variables in the project. If you want to customize these values, you can provide them as parameters when starting the project, as shown below:

| Variable Name | Default Value | Description |
|---------------|---------------|----------------------------|
| DB_HOST | localhost | MySQL host |
| DB_PORT | 3306 | MySQL port |
| SCHEMA_NAME | url | Project schema name |
| DB_USERNAME | root | MySQL username |
| DB_PASSWORD | root | MySQL password |
| CODE_LENGTH | 5 | Auto generated code length |

```shell
java -DCODE_LENGTH=10 -jar app.jar
```

### Setup with Docker

> **Prerequisites**
>
> - **Docker**: Docker must be installed on your local machine.

1. Clone the repo

```shell
git clone https://github.com/furkancelikk/url-shortener.git
```
2. Change the directory

```
cd url-shortener
```
3. Start the project. This command will pull the necessary dependencies, download MySQL as a container, and run the project.

```
docker compose up -d
```

You can access the project at port 8080.

**Note:** When starting the project with Docker, the following values are defined as environment variables. If you wish to customize these values, you can modify them in the [.env](.env) file.

| Variable Name | Value | Description |
|------------------------|---------------------|----------------------------|
| SERVICE_IMAGE_NAME | url-shortener | Project image name |
| SERVICE_CONTAINER_NAME | url-shortener | Project container name |
| SERVICE_PORT | 8080 | Project port |
| DB_CONTAINER_NAME | url-shortener-mysql | MySQL container name |
| DB_PORT | 3306 | MySQL port |
| DB_USERNAME | url-shortener | MySQL user name |
| DB_PASSWORD | p4ssword | MySQL password |
| DB_ROOT_PASSWORD | root | MySQL root password |
| SCHEMA_NAME | url-shortener | MySQL scheme name |
| CODE_LENGTH | 5 | Auto generated code length |

---

#### [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)