Code Monkey home page Code Monkey logo

urlshortener-rest-api's Introduction

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.

urlshortener-rest-api's People

Contributors

singhkshitij avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.