Skip to content

surjendu104/Shorty-URL-Shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shorty URL Shortener

This a URL Shortener app which you can easily add to your project with little bit of configuration.
Here are some functionality of the app

  1. This app is created in Java Springboot.
  2. This app takes long url and return short url which you can easily fire on web and go to the long url.
  3. It uses role based authentication.
  4. For authentication it uses email and password which you have used while signing up.
  5. JWT Token is used for authentication.
  6. One cool thing --> you can customize the length of short url key length.

Here is the sample authentication api call diagram !!

Auth api call diagram

Sample Api Calls

  1. Sign up request [POST]
Status Method URL Request Header Response
200 POST
http://localhost:8080/auth/signup
{
    "name":"John Doe",  
    "email":"john@gmail.com",
    "password":"john@1234"
}
NO User added header
{
    "id":1,
    "name":"John Doe",  
    "email":"john@gmail.com",
    "password":"$2a$10$uhUIUmVWVnrBWx9rrDWhS."
}
200 POST
http://localhost:8080/auth/login
{
    "email":"john@gmail.com",
    "password":"john@1234"
}
NO User added header
{
    "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.
            eyJlbWFpbCI6ImpvaG5AZ21haWwuY29tIiwic
            GFzc3dvcmQiOiJqb2huQDEyMzQifQ.ibVqO0r
            g6jwJ3uIEvZAeH_Ecg7T2bDW2lXeRJr2stW4",
    "username":"john@gmail.com"
}
401 POST
http://localhost:8080/auth/login
{
    "email":"john@gmail.com",
    "password":"john@12"
}
NO User added header
Bad Credentials !!
200 POST
http://localhost:8080/home/saveurl
{
    "originalUrl":"www.google.com"
}
Authorization : Bearer <JWT Token>
{
    "id":1,
    "originalUrl":"https://www.google.com",
    "shortUrl":"24WnSpXt",
    "creationDate":"2023-07-07T17:09:42.411",
    "expirationDate":" 2023-11-04T17:09:42.411"
}
200 POST
http://localhost:8080/home/get-user
No body
Authorization : Bearer <JWT Token>
{
    "id":1,
    "name":"John Doe",  
    "email":"john@gmail.com",
    "password":"$2a$10$uhUIUmVWVnrBWx9rrDWhS.",
    "roles":["NORMAL"],
    "urls": [
        {
            "id":1,
            "originalUrl":"https://www.google.com",
            "shortUrl":"24WnSpXt",
            "creationDate":"2023-07-07T17:09:42.411",
            "expirationDate":" 2023-11-04T17:09:42.411"
        }
    ]
}

Congfiuration

  1. Pull the docker image

    docker pull surjendu104/url-shortener-images:latest
  2. Run your mongodb server by running this in terminal

    mongod
  3. Run the container by setting enviorment variable

    docker run \
    -p 8080:8080 \
    -e DB_HOST=<YOUR_IP_ADDRESS> \
    -e DB_PORT=<MONGODB_PORT> \
    -e DB_COLLECTION=<MONGODB_COLLECTION_NAME> \
    -e JWT_SECRET=<JWT_SECRET> \
    -e SHORT_URL_KEY_LENGTH=<LENGTH_YOU_WANT> \
    surjendu104/url-shortener-images

    Sample command

    docker run \
    -p 8080:8080 \
    -e DB_HOST=192.168.0.119 \
    -e DB_PORT=27017 \
    -e DB_COLLECTION=url_shortener \
    -e JWT_SECRET="afafasfafafasfasfasfafacasdasfasxASFACASDFACASDFASFASFDAFASFASDAADSCSDFADCVSGCFVADXCcadwavfsfarvf" \
    -e SHORT_URL_KEY_LENGTH=4 \
    surjendu104/url-shortener-images

Resources

  1. Springboot docs
  2. Mongodb Guide
  3. Docker guide

Fell free to raise any issue and pr !!

That's it :)