GithubHelp home page GithubHelp logo

shortify's Introduction

shortify

A simple URL shortener.

Summary

Stack

  • Docker
  • SQLite
  • Rails 6.0.0
  • Ruby 2.6.5
  • Rspec

Tools

Lints

Ruby

Git

Setup

For this project, we use Docker and docker-compose. So if you want to run this project, be sure to have both installed before continuing.

You can follow this tutorial explaining how to install them.

Downloading and installation

To download and install this project, just run the following commands:

$ git clone [email protected]:rodrigo93/shortify.git
$ docker-compose up

This might take some minutes, depending on you internet speed to download the necessary images.

Running

All you need to do to run this project is running the following command in the root directory of this project:

$ docker-compose up

Wait for the build and shortify! :D

Available commands

dev/bash

Open a bash session inside a temporary shortify container.

dev/build

Build and run everything that is declared in Dockerfile.

dev/bundle-install

Runs bundle install inside a temporary shortify container.

dev/bundle-update

Runs bundle update inside a temporary shortify container.

dev/console

Open a rails console inside a container. By default it will open inside the shortify container.

dev/lint

Run all configured lints in the project.

dev/logs

Check log outputs from shortify container.

dev/restart

Restarts all containers from this project.

dev/rspec FILE_PATH

Run all RSpec tests or just the given specs passed in the FILE_PATH argument.

dev/start

Start all containers from this project.

dev/stop

Stop all containers from this project.

Endpoints

POST shorten

POST /shorten
Content-Type: "application/json"

{
  "url": "http://example.com",
  "shortcode": "example"
}
Attribute Description
url url to shorten
shortcode preferential shortcode

Returns

201 Created
Content-Type: "application/json"

{
  "shortcode": :shortcode
}

A random shortcode is generated if none is requested, the generated short code has exactly 6 alpahnumeric characters and passes the following regexp: ^[0-9a-zA-Z_]{6}$.

Errors

Error Description
400 url is not present
409 The the desired shortcode is already in use. Shortcodes are case-sensitive.
422 The shortcode fails to meet the following regexp: ^[0-9a-zA-Z_]{4,}$.

GET shorten

GET /:shortcode
Content-Type: "application/json"
Attribute Description
shortcode url encoded shortcode

Returns

302 response with the location header pointing to the shortened URL

HTTP/1.1 302 Found
Location: http://www.example.com

Errors

Error Description
404 The shortcode cannot be found in the system

GET stats

GET /:shortcode/stats
Content-Type: "application/json"
Attribute Description
shortcode url encoded shortcode

Returns

200 OK
Content-Type: "application/json"

{
  "start_date": "2012-04-23T18:25:43.511Z",
  "last_seen_date": "2012-04-23T18:25:43.511Z",
  "redirect_count": 1
}
Attribute Description
start_date date when the url was encoded, conformant to ISO8601
redirect_count number of times the endpoint GET /shortcode was called
last_seen_date date of the last time the a redirect was issued, not present if redirect_count == 0

Errors

Error Description
404 The shortcode cannot be found in the system

shortify's People

Contributors

rodrigo93 avatar dependabot[bot] avatar

Stargazers

Mateus Rissi 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.