Skip to content

nardonykolyszyn/shortener_rails_api

Repository files navigation

Shortener API

This API implements a HTTP client that connects Bit.ly API

API url: https://api-shorten-test.herokuapp.com

This API allows you to:

  • Shorten URLs

  • Get information about a shortened URL

  • Get stadistics of a certain shortened URL

  • Get all URLs previously created

Usage

Shorten an URL

  POST /api/v1/links/shorten

It shorten and returns a new url

Payload

  {
    "url": "http://google.com"
  }

Success ✅

HTTP 200

 "status_code": 200,
 "status_txt": "OK",
 "data": {
   "url": "http://bit.ly/2NeKoad",
   "hash": "2NeKoad",
   "global_hash": "3j4ir4",
   "long_url": "http://google.com/",
   "new_hash": 0
 }

Errors ❌

HTTP 422

{
    "error": "missing url param",
    "code": "unprocessable_entity"
}
  GET /api/v1/links/

It returns all urls previously created

HTTP 200

{
{
        "id": 1,
        "response": {
            "status_code": 200,
            "status_txt": "OK",
            "data": {
                "url": "http://bit.ly/2BJQL0z",
                "hash": "2BJQL0z",
                "global_hash": "2BFSAvy",
                "long_url": "http://bitconcept.io/",
                "new_hash": 0,
                "title": "Bit Concept"
            }
        },
        "created_at": "2019-03-11T19:47:43.577Z",
        "updated_at": "2019-03-11T19:47:43.577Z"
 },
{
        "id": 2,
        "response": {
            "status_code": 200,
            "status_txt": "OK",
            "data": {
                "url": "http://bit.ly/2BJQL0z",
                "hash": "2BJQL0z",
                "global_hash": "2BFSAvy",
                "long_url": "http://bitconcept.io/",
                "new_hash": 0,
                "title": "Bit Concept"
            }
        },
        "created_at": "2019-03-11T19:47:43.577Z",
        "updated_at": "2019-03-11T19:47:43.577Z"
    }
 }

Errors ❌

HTTP 422

{
    "error": "missing url param",
    "code": "unprocessable_entity"
}

Installing

This API uses Rails 5.2.2 and Ruby 2.4.1

Open your favorite Terminal and run these commands.

  1. Clone repository
$ git clone https://github.com/devpolish/shortener_rails_api.git
  1. Installing dependencies
$ cd shortener_rails_api

$ RAILS_ENV=development bin/bundle install
  1. Create databases
$ rake db:migrate

Testing

$ rspec specs/*

About

A simple API that connects to Bit.ly services

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published