Coders Packet

URL Shortener using Java, Spring, and Redis

By Alwis Guru K V

An URL shortening Service developed with Java with spring framework and Redis. The packet takes an URL as input and generates a base62 short URL. It also redirects to the original URL.

TITLE: URL-Shortening Service

OBJECTIVE: To get a short URL to share among others rather than a long URL

BUILD TOOLS:

# Java

# Spring

# Maven

#Spring MVC

# Redis

# Spring Data Redis

# Spring Boot

# Thymeleaf

SYSTEM REQUIREMENTS:

Redis Server (See the official website to install Redis based on your OS distro and make sure it is active during execution)

Redis Status

DESCRIPTION:

              This spring-boot web app works based on the MVC design principle. All the services are coded in an Interface pattern to modify in the future simply for other developers.

# APP CONFIGURATION:

               This web app is configured to use the Jedis client for accessing the Redis database deployed in your OS/server. The packet uses two Redis templates offered by the Spring Redis Data and Jedis connection factory to create and access unique short URLs. 

# REPOSITORIES:

              Two repositories, one for unique id to create base62 short id and another for saving the URL to its corresponding short URL. These repositories implement require database actions to shorten and retrieve URLs.

# SERVICES:

             When a user submits an URL, the validator service will check whether the URL is valid or not. If not valid, it will show invalid. After validation, the shortening service will get a unique id from the Redis database and convert it into base62 to shorten the length of the short URL and map it with the original URL in the database using the repositories created.

#CONTROLLERS:

            The controller takes control of the HTTP request to show the URL form and return the shortened URL to the user throw view elements provided by the Thymeleaf template engine. When the user enters the short URL in the browser, the controller redirects the request to the original URL.

INSTRUCTIONS:

Setup Redis in your system by visiting the official Redis page.

# Open the project folder and follow the instructions based on your OS

#LINUX/MAC

./mvnw spring-boot:run

#WINDOWS

mvnw.cmd spring-boot:run

# Open any browser and paste the URL

http://localhost:8080/shorter

# To retrieve, append the short URL in the above link as

http://localhost:8080/shorter/oqE

 

SCREENSHOTS:

URL form

Result Page

Redirect

MODIFICATIONS:

You can add a feature to check the URL before submitting for a better user experience

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by Alwis Guru K V (kvalwis)

Download packets of source code on Coders Packet