HTTP service for shortening URLs like Bitly etc. Available saving URLs and getting short name for redirecting. Also, you can give your own shortened name for saving URL.
Shortened name is random-generated string of letters and digits with specified length.
Application uses MariaDB for saving data.
Application can be used in three ways. In two ways except of already completed Docker Compose config, you must set up MariaDB. For using application, you should read about endpoints.
Application can be used via Docker Compose. If you want to use already completed Docker Compose config you should do this:
- Clone the repository and go to the repository's directory:
git clone https://github.com/volk0v/url-shortener.git && cd url-shortener
- Run the services (url-shortener and mariadb) by using Docker Compose config:
docker-compose up -d
Done, now you can connect it via your own IP address or localhost.
You can build a Docker image and use it by your way, for it, you should do this:
- Clone the repository and go to the repository's directory:
git clone https://github.com/volk0v/url-shortener.git && cd url-shortener
- Build an image:
docker build -t url-shortener:latest
- Create container and start application:
docker run -p 80:8080 -d url-shortener:latest
Done, now you can connect it via your own IP address or localhost.
You can build a jar file, for it, you should do this:
- Clone the repository and go to the repository's directory:
git clone https://github.com/volk0v/url-shortener.git && cd url-shortener
- Run Maven for build jar file:
./mvnw clean package
- Now you built jar file which is in target directory. Run it:
java -jar target/url-shortener*.jar
Done, now you can connect it via your own IP address or localhost and you should use port 8080!
Use it for creating shortened name for your URL.
Body for creating random-generated shortened name:
{
"referenceUrl": "https://example.net"
}
Body for creating your own shortened name:
{
"referenceUrl": "https://example.net",
"shortenedName": "example"
}
Response is JSON with reference URL and shortened name (random-generated or your own):
{
"referenceUrl": "https://example.net",
"shortenedName": "example"
}
Use it for get redirect to your reference URL.
You can change the length of random-generated shortened name by setting up the environment url-shortener.random-url-length. By standard, it set up for seven characters. Example:
url-shortener.random-url-length=10
You must set up database configuration by setting environment variables: DB_URL, DB_USERNAME, DB_PASSWORD. Example:
DB_URL=jdbc:mariadb://localhost/app_database
DB_USERNAME=app_user
DB_PASSWORD=P@ssw0rd