Skip to content

PrateekxCodes/url-shortener

Repository files navigation

URL Shortener

This is a url shortener API, build with Ruby On Rails 6.

App is deployed here

Screenshot

Screenshot 2022-06-22 at 7 05 28 PM

How to use URL-Shortner

  1. Clone the repository by running the following command
$ git clone https://github.com/PrateekCodes/url-shortener.git
  1. Now, go to the cloned directory
$ cd url-shortener
  1. Install dependencies by running the following commands
$ bundle install
  1. Setup the database
$ rails db:create db:migrate db:setup
  1. Create .env file in root
$ echo ROOT_URL=http://localhost:3000/ >> .env
  1. Now we can execute following commands.
$ URL=https://bigbinary.com/jobs bundle exec rake app:encode

$ SHORTURL=https://localhost:3000/tkLo2367 bundle exec rake app:decode

How rake tasks works

URL=https://bigbinary.com/jobs bundle exec rake app:encode

The above rake task should print following statement in the terminal.

The shortened url of https://bigbinary.com/jobs is https://short.is/tkLo2367`.
SHORTURL=https://short.is/tkLo2367 bundle exec rake app:decode

The above task should print following statemetn in the terminal.

The original url of short url https://short.is/tkLo2367 is https://bigbinary.com/jobs

If the SHORTURL is not present in the database then print error message like shown below.

No original url was found for the  short url https://short.is/poliwe71

To deletes all records and populates sample data

rake setup_sample_data

Implementation

  • Added pinned column in urls table with boolean value type and default value is false.

  • On /api/v1/urls endpoint index action called and sent:-

    • List of all urls sent in Json format.
    • List order created in descending order based on value updated_at
    • All pinned item with value true moved to top.
  • Added CRUD for categories over REST api of categories.

  • Url's can be assigned different categories.

  • On /api/v1/urls endpoint for categories:-

    • list of urls with default alloted categories
    • categories can be alloted again.

EndPoints

Url EndPoints

index:
  method: "GET"
  path: "/api/v1/urls"

create:
  method: "POST"
  path: "/api/v1/urls"
  params: url: { original: "https://twitter.com" }

show:
  method: "GET"
  path: "/api/v1/urls/:short"

update:
  method: "PUT"
  path: "api/v1/urls/:short"
  params: url: { pinned: true }

Category EndPoints

index:
  method: "GET"
  path: "/api/v1/categories"

create:
  method: "POST"
  path: "/api/v1/categories"
  params: category: { title: "blog", color: "#ffffff" }

destroy:
  method: "DELETE"
  path: "/api/v1/categories/:title"

update:
  method: "PUT"
  path: "api/v1/categories/:title"
  params: category: { title: "blog", color: "#ffffff" }

Report EndPoints

index:
  method: "GET"
  path: "/api/v1/reports"

About

This is a url shortener, build with React and Ruby On Rails 6.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published