Giter Club home page Giter Club logo

url-shortener's Introduction

README

Ruby version

3.2.2

Setup Project

  $ cp .env_example .env
  • Update your own values
  $ bundle install
  $ rails db:create
  $ rails db:migrate

Create user & get your own token by rake, or you can create manual in rails console.

  $ bundle exec rake one_time:create_user

Using

You can use Postman app to request API or curl commands.
For Heroku testing. Use this token -XzFmMW7PLMu5ezgf7pZRZhqb11rtZ-TJDIXzxrF6uA

API to encode original url

POST /api/v1/encode

  $ curl --location --request POST 'https://dungph-url-shortener.herokuapp.com/api/v1/encode' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer -XzFmMW7PLMu5ezgf7pZRZhqb11rtZ-TJDIXzxrF6uA' \
  --data-raw '{"original_url": "https://google.com"}'

API to decode short url

POST /api/v1/decode

  $ curl --location --request POST 'https://dungph-url-shortener.herokuapp.com/api/v1/decode' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer -XzFmMW7PLMu5ezgf7pZRZhqb11rtZ-TJDIXzxrF6uA' \
  --data-raw '{"short_url": "https://dungph-url-shortener.herokuapp.com/FZal6"}'

Testing

$ bundle exec rspec

Real life problem

In my point of view, to adapt all real life situations, we can

  • Add authentication and authorization: Add user authentication and authorization to ensure that only authorized users can access the shortener service. This can be done using popular authentication and authorization libraries like Devise and CanCanCan.
  • Add user dashboard: Provide a user dashboard where users can view their short links, track clicks, and manage their short links. This can be done using a simple dashboard built using Bootstrap or a more advanced dashboard using a third-party library like ActiveAdmin.
  • Add analytics: Add analytics to track clicks, locations, and devices used to access the short links. This can be done using a third-party analytics service like Google Analytics or a self-hosted analytics tool like Matomo.
  • Improve performance: Improve the performance of the app by optimizing the database queries, using a caching layer, and minimizing the use of external resources.

url-shortener's People

Watchers

Dung Phan 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.