Skip to content

Just another url shortner REST API written on Spring Boot with Maven and Redis

License

Notifications You must be signed in to change notification settings

singhkshitij/UrlShortener-REST-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UrlShortener REST API

A Java based API Service built with Spring Boot, and Redis and deployed on Heroku.

Deploy Heroku App Status

How to run locally !

  • Prerequisites :
    • A local redis instance instance should be up and running before running our service.
  • Import the maven project in eclipse
  • Navigate to URLRepository class and replace
reJedis = new SpringConfig().getJedisPool().getResource();

with

reJedis = new redis();
  • Now go to application.java and run as java application
  • Your server is up and running now.
  • By default the Server will run on localhost:8080/shortener
  • To test, send POST Request to localhost:8080/shortener with a body of type application/json with body { 'url' : '' }

To Package as a Spring Boot jar !

  • Build the project with mvn clean package
  • Goto target folder you get a packaged jar to deploy whereever you want. :)

How to deploy on Heroku !

  • Create a Heroku account.
  • Install the Heroku CLI.
  • Set up Heroku locally using your
Heroku login. 
  • Once it is done, the steps are straightforward
git init
git add .
git commit -m "initial commit"
 
# creates a heroku application with random name (and Domain)
# creates a git repository at heroku
# registers the remote repository by the name heroku
heroku create
 
#Pushes the source code to the heroku git repo, so heroku can build and deploy it
git push heroku master
 
#opens our app in a browser 
heroku open
  • Now our application is up and running but we have not deployed any redis instance for our application
  • Search for Heroku redis in add on section from dashboard.
  • click on install.
  • Now verify if redis is up and running by typing
$ heroku config
#You should get the similar output
REDIS_URL: redis://h:[email protected]:111
  • Note : Now the most important step is to disable connection pool timout for redis instance otherwise our pool get terminated by default after 5 min.
  • on console type
heroku redis:timeout redis-elliptical-39032 --seconds 0
  • Here redis-elliptical-39032 is redis instance name.
  • If you get the following output. Voila your REST API is up and running with full functionality enabled. You can try hitting the api endpoints now.
How Heroku Works ?

After pushing code to the remote repository named Heroku, the build process is triggered. Given that the project has a pom.xml, Heroku recognizes it as a Java application. Spring Boot has an embedded Tomcat. Therefore, it can be started up as a JAR file and will work as a web server.

About

Just another url shortner REST API written on Spring Boot with Maven and Redis

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages